Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being black and 0 being white. 

Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2n by 2n. You are allowed to move pieces but not allowed to rotate or flip them.

Input

The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board. 

Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.

Output

Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.

Examples

Input

1
0

0

1

0


Output

1


Input

3
101
010
101

101
000
101

010
101
011

010
101
010


Output

2
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x961C
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[][][] grid = new int[4][N][N];
         for(int t=0; t < 4; t++)
         {
            for(int r=0; r < N; r++)
            {
               String input = infile.readLine();
               for(int c=0; c < N; c++)
                  if(input.charAt(c) == '1')
                     grid[t][r][c]++;
            }
            if(t+1 < 4)
               infile.readLine();
         }
         //cancer
         int[][] cnt = new int[4][2];
         for(int t=0; t < 4; t++)
         {
            int[][] curr = grid[t];
            int cnt1 = 0; //white start
            int cnt2 = 0; //black start
            for(int r=0; r < N; r++)
               for(int c=0; c < N; c++)
               {
                  if((r+c)%2==0)
                  {
                     if(curr[r][c] == 1)
                        cnt1++;
                     else
                        cnt2++;
                  }
                  else
                  {
                     if(curr[r][c] == 0)
                        cnt1++;
                     else
                        cnt2++;
                  }
               }
            cnt[t][0] = cnt1;
            cnt[t][1] = cnt2;
         }
         int res = 4*N*N;
         for(int a=0; a < 4; a++)
            for(int b=0; b < 4; b++)
               for(int c=0; c < 4; c++)
                  for(int d=0; d < 4; d++)
                     if(a != b && b != c && a != c && a != d && b != d && c != d)
                     {
                        int temp = cnt[a][0]+cnt[b][1]+cnt[c][0]+cnt[d][1];
                        temp = Math.min(temp, cnt[a][1]+cnt[b][0]+cnt[c][1]+cnt[d][0]);
                        res = Math.min(res,temp);
                     }
         System.out.println(res);
      }
   }