Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, you can twist it 90 degrees in clockwise or counterclockwise direction, this twist operation is called one twist step.

Considering all faces of mini-cubes, there will be totally 24 faces painted in 6 different colors (Indexed from 0), and there will be exactly 4 faces painted in each kind of color. If 4 mini-cubes' faces of same color rely on same large cube face, we can call the large cube face as a completed face.

Now giving you an color arrangement of all 24 faces from a scrambled Pocket Cube, please tell us the maximum possible number of completed faces in no more than `N` twist steps.

Index of each face is shown as below:

There will be several test cases. In each test case, there will be 2 lines. One integer `N` (1 ≤ `N` ≤ 7) in the first line, then 24 integers `C _{i}` seperated by a sinle space in the second line. For index 0 ≤

For each test case, please output the maximum number of completed faces during no more than `N` twist step(s).

提交代码