#00051C

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
BBBBBBBBB
BBBBBBBBB
PPPPPPPPP
PPPPPPPPP

CCCCCCCCC
CCCCCCCCC
BBBBBBBBB
BBBBBBBBB
CCCCCCCCC
CCCCCCCCC

ZZZBBBCCC
ZZZBBBCCC
ZZZBBBCCC
ZZZBBBCCC
ZZZBBBCCC
ZZZBBBCCC

ZZZAAAZZZ
ZZZAAAZZZ
ZZZAAAZZZ
ZZZAAAZZZ
ZZZAAAZZZ
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.


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

OutputOutput one integer, flag similarity measure for given matrix.

Input
CCCCCCCCC
CCCCCCCCC
CBBBBBBBC
PBBBBBBBP
PPPPPPPPP
PPPPPPPPP

Output
4

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.