题目描述
Problem Description
Chikuma Paken is about to face the Paken War in the near future. Therefore, they have decided to create a military flag.
The design of the flag is represented by a grid of $5$ rows and $N$ columns, forming a $5 \times N$ grid. The cell at the $i$-th row and $j$-th column is denoted as $(i, j)$.
Currently, each cell of the flag is painted in one of the colors: red, blue, white, or black. More specifically, cell $(i, j)$ is painted in color $S_{i, j}$, where $S_{i, j}$ is one of R, B, W, #, representing red, blue, white, and black, respectively.
E869120 wants to repaint the Paken military flag to satisfy the following conditions:
- In every column of $N$ columns, all $5$ cells must be either "all blue", "all white", or "all red".
- Any two adjacent columns must have different colors.
Note that the presence of a black cell means the condition is not satisfied.
Below are examples of flags that either satisfy or do not satisfy the conditions:

- Example $1$ satisfies the conditions.
- Example $2$ does not satisfy the conditions, for instance, the second column from the left has both blue and white cells, which violates the requirement that all $5$ cells in a column must be the same color.
- Example $3$ does not satisfy the conditions, for instance, the third and fourth columns from the left have the same color, which violates the requirement that adjacent columns must have different colors.
- Example $4$ does not satisfy the conditions, for instance, the fifth column from the left contains a black cell, which violates the condition.
E869120 wants to minimize the number of cells to be repainted to shorten the flag creation time. Write a program to determine the minimum number of cells that need to be repainted.
Input Format
The input is given from the standard input in the following format:
Note that the color information $S_{i, 1}, S_{i, 2}, S_{i, 3}, \dots, S_{i, N}$ for each row is given as a single $N$-character string.
$N$ $S_{1, 1} S_{1, 2} S_{1, 3} \cdots S_{1, N}$ $S_{2, 1} S_{2, 2} S_{2, 3} \cdots S_{2, N}$ $S_{3, 1} S_{3, 2} S_{3, 3} \cdots S_{3, N}$ $S_{4, 1} S_{4, 2} S_{4, 3} \cdots S_{4, N}$ $S_{5, 1} S_{5, 2} S_{5, 3} \cdots S_{5, N}$
Output Format
Output the minimum number of cells that need to be repainted to create the Paken military flag in one line.
Sample Input and Output
Sample Input #1
1
B
R
#
W
B
Sample Output #1
3
Sample Input #2
3
WWR
#RW
BW#
##B
RBR
Sample Output #2
10
Sample Input #3
8
RRRRRRRR
########
BBBBBBBB
RRRRRRRR
WWWWWWWW
Sample Output #3
28
Sample Input #4
7
BR#WB#R
RWW#WRB
##WBR#W
WB#B#RW
BRW##BB
Sample Output #4
21
Notes/Hints
Constraints
All input data satisfies the following constraints:
- $N$ is an integer satisfying $1 \leq N \leq 999$
- $S_{i, j}$ is one of
R,B,W,#
Partial Points
This problem is divided into several sub-tasks, and your score is the sum of the points for the sub-tasks you solve correctly.
- (11 points) $N = 1$
- (13 points) $N = 3$
- (29 points) $N \leq 10$
- (22 points) All $N$ cells in each of the $5$ rows are the same color.
- (25 points) No additional constraints.
Note for sub-task $4$: Be careful not to misread the condition as "In every column of $N$ columns, all $5$ cells must be the same color."
Sample Explanation 1
There are $3$ possible ways to create the Paken military flag:
- Paint all cells red. Then, $4$ cells $(1, 1), (3, 1), (4, 1), (5, 1)$ need to be repainted.
- Paint all cells blue. Then, $3$ cells $(2, 1), (3, 1), (4, 1)$ need to be repainted.
- Paint all cells white. Then, $4$ cells $(1, 1), (2, 1), (3, 1), (5, 1)$ need to be repainted.
Among these, painting all cells blue is the best option, requiring repainting $3$ cells. This example satisfies the constraints of sub-task $1$ since $N = 1$.
Sample Explanation 2
Painting the first column blue, the second column white, and the third column red can minimize the number of cells to be repainted to $10$, which is optimal.
(Here, "★" represents a repainted cell)
This example satisfies the constraints of sub-task $2$ since $N = 3$.
Sample Explanation 3
The optimal way to repaint is shown in the following figure. The number of cells to be repainted is $28$.

Sample Explanation 4
The optimal way to repaint is shown in the following figure. The number of cells to be repainted is $21$.

输入格式
见题面 Input 部分
输出格式
见题面 Output 部分