ZASTAVE
문제
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