BOMBONI | 프로그래밍의 벗 PivotOJ
PivotOJ

BOMBONI

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2012 Junior Croatian Olympiad in Informatics - Exam #1BOJ 3085

문제

Little Ivan is bored at math class so he decided to play popular game called "Bomboni". At the beginning all fields of N×N square board contain candies (not necessarily of same color). When its his turn player should swap two neighbouring (up, down, left or right) candies of different color and then pick some sequence (in row or column) of same color candies which he will take and eat. 

Initial board configuration is given, help Ivan and write a program which will calculate maximal number of candies he can win in the first move. 

입력

In the first line of standard input there is one integer N (3 ≤ N ≤ 50), board dimensions. 

In next N lines initial board configuration is given, j-th character in i-th row denotes color of candy at square (i, j) : C (red), P (blue), Z (green), Y (yellow). It will always be possible to make first move. 

출력

In the first and only line of standard output print the maximal number of candies Ivan can win in the first move. 

힌트

Second test example explanation: in first row we see sequence PPPP, so swapping any two candies in other rows first row remain unchanged so Ivan can take it.

Third test example explanation: swapping candies Y and C in 4th row Ivan gets sequence CCCC in first column.

예제

예제 1

입력
3
CCP
CCP
PPC
출력
3

예제 2

입력
4
PPPP
CYZY
CCPY
PPCC
출력
4

예제 3

입력
5
YCPZY
CYZZP
CCPPP
YCYZC
CPPZZ
출력
4
코드를 제출하려면 로그인하세요.