spoj#DOMINO1. The Longest Chain of Domino Tiles

The Longest Chain of Domino Tiles

You are given N domino tiles. Each tile is made of some number of squares (not necessarily two), and each square is coloured either white or black (we use the Croatian letters: B for white and C for black).

Find the longest chain that can be made of these tiles. Each tile can be used at most once and cannot be rotated (for example, BC cannot become CB). The chain is made by a common rule: in adjacent tiles, touching squares must be of the same colour.

Input

[N ≤ 100, the number of dominoes]

in the next N lines:

[a string of size between 1 and 100, representing the domino]

Output

The length of the longest chain.

Example

Input:
4
CB
BCC
BBCC
BCBBC
Output:
11