ZASTAVE | 프로그래밍의 벗 PivotOJ
PivotOJ

ZASTAVE

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2010 School Competition - SeniorsBOJ 3100

문제

Ante is developing a flag recognition system. After a series of filters and algorithms we get a 6×9 matrix of characters where same character denotes same color. 

The system is in the initial phase of development, so Ante has set a goal to recognize simple flags like these:

CCCCCCCCC     CCCCCCCCC     ZZZBBBCCC     ZZZAAAZZZ
CCCCCCCCC     CCCCCCCCC     ZZZBBBCCC     ZZZAAAZZZ
BBBBBBBBB     BBBBBBBBB     ZZZBBBCCC     ZZZAAAZZZ
BBBBBBBBB     BBBBBBBBB     ZZZBBBCCC     ZZZAAAZZZ
PPPPPPPPP     CCCCCCCCC     ZZZBBBCCC     ZZZAAAZZZ
PPPPPPPPP     CCCCCCCCC     ZZZBBBCCC     ZZZAAAZZZ

In other words, simple flags that ante is considering consists of three equal stripes horizontally or vertically. The color on the middle stripe must differ from the colors on other two stripes. 

For each matrix, we define a flag similarity measure as the minimum number of cells that need to be replaced by other characters for the matrix to become a simple flag. 

Write a program that calculates a flag similarity measure for given matrix. 

입력

Six lines contains nine upper case english letters each, the matrix. 

 

출력

Output one integer, flag similarity measure for given matrix. 

 

예제

예제 1

입력
CCCCCCCCC
CCCCCCCCC
CBBBBBBBC
PBBBBBBBP
PPPPPPPPP
PPPPPPPPP
출력
4

예제 2

입력
AZZAAAMMA
AZZAAAMMA
ZZZAMAMMM
ZZZAAAMMM
AZZAAAMMA
AZZAAAMMA
출력
9

예제 3

입력
TAAAOAAAT
AAAOAOAAA
OOOAAAOOO
OOOAAAOOO
AAAOAOAAA
TAAAOAAAT
출력
16
코드를 제출하려면 로그인하세요.