Flag Recognition

Time limit1sMemory limit128 MB

Problem

Huiwon built a flag recognition system. The system filters a flag into a 6*9 matrix and then recognizes it. Each cell of the matrix contains an uppercase letter representing a color.

Because the system is still in an early stage, it can recognize only simple flags split into three parts, as shown below.

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

A simple flag is a 6*9 matrix split into three horizontal parts of 2 rows each, or into three vertical parts of 3 columns each, such that every cell in each part has the same color. The color of the middle part must be different from the colors of both outer parts. The two outer parts may have the same color or different colors.

Given a recognized flag, write a program that finds the minimum number of characters that must be changed to make it a simple flag.

Input

Six lines are given. Each line contains 9 uppercase English letters.

Output

Print the minimum number of characters that must be changed to make the flag simple.