P26732 [AtCoder] Poster
普及
题目描述

Problem Description

JOI has made a poster to promote his class's project at the school festival. The poster is in the shape of an N x N grid, with each cell painted either red, green, or blue. The color of the cell at the i-th row from the top and the j-th column from the left (1 ≤ i ≤ N, 1 ≤ j ≤ N) is red if $ S_{i,j}= $R, green if $ S_{i,j}= $G, and blue if $ S_{i,j}= $B.

However, his classmates were not satisfied with this poster. After discussion, it was decided to create a new poster by changing the color arrangement without changing the grid shape. The color of the cell at the i-th row from the top and the j-th column from the left (1 ≤ i ≤ N, 1 ≤ j ≤ N) in the new poster should be red if $ T_{i,j}= $R, green if $ T_{i,j}= $G, and blue if $ T_{i,j}= $B.

JOI decided to create the new poster by repeatedly performing one of the following operations on the current poster:

  • Choose a cell and repaint it to any color.
  • Rotate the entire poster 90° clockwise. In this case, the cell originally at the i-th row and j-th column (1 ≤ i ≤ N, 1 ≤ j ≤ N) will move to the j-th row and (N-i+1)-th column.
  • Rotate the entire poster 90° counterclockwise. In this case, the cell originally at the i-th row and j-th column (1 ≤ i ≤ N, 1 ≤ j ≤ N) will move to the (N-j+1)-th row and i-th column.

Each operation takes 1 minute. Given the information about the poster JOI made and the new poster to be created, write a program to determine the minimum time required for JOI to create the new poster.

Input Format

The input is given from the standard input in the following format:

$ N $ $S_{1,1}\ \cdots\ S_{1,N}$ $\vdots$ $S_{N,1}\ \cdots\ S_{N,N}$ $T_{1,1}\ \cdots\ T_{1,N}$ $\vdots$ $T_{N,1}\ \cdots\ T_{N,N}$

Output Format

Output the minimum time required to create the new poster in one line.

Sample Input and Output

Sample Input #1

3
RRR
GGG
BBB
RRR
RRR
RRR

Sample Output #1

6

Sample Input #2

3
RRR
GGG
BBB
RGB
RGB
RGB

Sample Output #2

1

Sample Input #3

6
RRRBBB
RRRBBB
RRRBBB
GGGRRG
GGGRRG
GGGBBR
RRRGGG
RRRGGG
RRRGGG
BBBRRB
BBBRRB
BBBGGR

Sample Output #3

10

Notes/Hints

Constraints

  • $1\ \leqq\ N\ \leqq\ 500$.
  • $ S_{i,j} $ is either R, G, or B.
  • $ T_{i,j} $ is either R, G, or B.

Sample Explanation 1

It is sufficient to repaint all the cells in the 2nd and 3rd rows to red. This takes 6 minutes.

Sample Explanation 2

It is sufficient to rotate the entire poster 90° counterclockwise. This takes 1 minute.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 RRR GGG BBB RRR RRR RRR
样例输出
6