Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 2131
Bejewlled

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Bejewlled is one of my favourite games of Fantasy Games series. In the game there are 64 different gems arranged in the form of a 8 * 8 square at the initial situation. Each time you can swap adjacent gems to create sets, either horizontal or vertical, of 3 or more identical gems. Then the sets will disappear and new gems will fall into place, possibly creating a chain reaction or 'cascade' of more sets.

Your task is very simple: analyze a situation and tell me how many gems disappear one swapping can make at most. It is guaranteed that there are no any horizontal or vertical sets of 3 or more identical gems in the situation.

Input

Input contains multiple test cases. Each test case has 8 lines, each line consists of 8 capital letters. Different letters specify different sorts of gems. Every test case will be followed by a blank line.

Output

There is one line for each test case, which is the maximum number of gems one swapping can make disappear at most.

Sample Input

AABBAABB
AABBAABB
BBAABBAA
BBAABBAA
AABBAABB
AABBAABB
BBAABBAA
BBAABBAA

AABBAABB
BBAABBAA
AABBAABB
BBAABBAA
AABBAABB
BBAABBAA
AABBAABB
BBAABBAA

Sample Output

6
6

Homepage: http://fairyair.yeah.net/

Each spirit has a own psychic world. The world we share is just a rule. Substance and soul are the same thing essentially.


Author: CHEN, Shixi
Source: Online Contest of Fantastic Game
Submit    Status