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
import java.util.*;
import java.io.*;
public class App
{
    public static boolean check(int x,int y)
    {
        if(x == y)
            return true;
        else
            return false;
    }
    public static void main(String[] args) throws Exception
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] a1 = new int[n+1][n+1];
        int[][] a2 = new int[n+1][n+1];
        int[][] a3 = new int[n+1][n+1];
        int[][] a4 = new int[n+1][n+1];
        int[][] arr = new int[2*n+2][2*n+2];
        boolean done = false;
        for(int i=1;i<=2*n;i++)
        {
            if(i%2 != 0)
            {
                for(int j=1;j<=2*n;j++)
                {
                    if(done == false)
                    {
                        done = true;
                        arr[i][j] = 1;
                    }
                    else
                    {
                        done = false;
                        arr[i][j] = 0;
                    }
                }
            }
            else
            {
                for(int j=1;j<=2*n;j++)
                {
                    if(done == false)
                    {
                        done = true;
                        arr[i][j] = 0;
                    }
                    else
                    {
                        done = false;
                        arr[i][j] = 1;
                    }
                }
            }
        }
        /*for(int i=1;i<=2*n;i++)
        {
            for(int j=1;j<=2*n;j++)
            {
                System.out.print(arr[i][j]);
            }
            System.out.println();
        }*/
        for(int i=1;i<=n;i++)
        {
            String[] str = (br.readLine()).trim().split("");
            for(int j=1;j<=n;j++)
                a1[i][j] = Integer.parseInt(str[j-1]);
        }
        String[] str1 = (br.readLine()).trim().split("");
        for(int i=1;i<=n;i++)
        {
            String[] str = (br.readLine()).trim().split("");
            for(int j=1;j<=n;j++)
                a2[i][j] = Integer.parseInt(str[j-1]);
        }
        str1 = (br.readLine()).trim().split("");
        for(int i=1;i<=n;i++)
        {
            String[] str = (br.readLine()).trim().split("");
            for(int j=1;j<=n;j++)
                a3[i][j] = Integer.parseInt(str[j-1]);
        }
        str1 = (br.readLine()).trim().split("");
        for(int i=1;i<=n;i++)
        {
            String[] str = (br.readLine()).trim().split("");
            for(int j=1;j<=n;j++)
                a4[i][j] = Integer.parseInt(str[j-1]);
        }
        int[] co1 = new int[5];
        int[] co2 = new int[5];
        int[] co3 = new int[5];
        int[] co4 = new int[5];
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(!check(arr[i][j],a1[i][j]))
                    co1[1]++;
                if(!check(arr[i][j],a2[i][j]))
                    co2[1]++;
                if(!check(arr[i][j],a3[i][j]))
                    co3[1]++;
                if(!check(arr[i][j],a4[i][j]))
                    co4[1]++;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(!check(arr[i][j+n],a1[i][j]))
                    co1[2]++;
                if(!check(arr[i][j+n],a2[i][j]))
                    co2[2]++;
                if(!check(arr[i][j+n],a3[i][j]))
                    co3[2]++;
                if(!check(arr[i][j+n],a4[i][j]))
                    co4[2]++;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(!check(arr[i+n][j],a1[i][j]))
                    co1[3]++;
                if(!check(arr[i+n][j],a2[i][j]))
                    co2[3]++;
                if(!check(arr[i+n][j],a3[i][j]))
                    co3[3]++;
                if(!check(arr[i+n][j],a4[i][j]))
                    co4[3]++;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(!check(arr[i+n][j+n],a1[i][j]))
                    co1[4]++;
                if(!check(arr[i+n][j+n],a2[i][j]))
                    co2[4]++;
                if(!check(arr[i+n][j+n],a3[i][j]))
                    co3[4]++;
                if(!check(arr[i+n][j+n],a4[i][j]))
                    co4[4]++;
            }
        }
        int[] per = new int[25];
        per[1] = co1[1] + co2[2] + co3[4] + co4[3];
        per[2] = co1[1] + co2[4] + co3[2] + co4[3];
        per[3] = co1[1] + co2[3] + co3[2] + co4[4];
        per[4] = co1[1] + co2[2] + co3[3] + co4[4];
        per[5] = co1[1] + co2[4] + co3[3] + co4[2];
        per[6] = co1[1] + co2[3] + co3[4] + co4[2];
        per[7] = co2[1] + co1[2] + co3[4] + co4[3];
        per[8] = co2[1] + co1[4] + co3[2] + co4[3];
        per[9] = co2[1] + co1[3] + co3[2] + co4[4];
        per[10] = co2[1] + co1[2] + co3[3] + co4[4];
        per[11] = co2[1] + co1[4] + co3[3] + co4[2];
        per[12] = co2[1] + co1[3] + co3[4] + co4[2];
        per[13] = co3[1] + co2[2] + co1[4] + co4[3];
        per[14] = co3[1] + co2[4] + co1[2] + co4[3];
        per[15] = co3[1] + co2[3] + co1[2] + co4[4];
        per[16] = co3[1] + co2[2] + co1[3] + co4[4];
        per[17] = co3[1] + co2[4] + co1[3] + co4[2];
        per[18] = co3[1] + co2[3] + co1[4] + co4[2];
        per[19] = co4[1] + co2[2] + co3[4] + co1[3];
        per[20] = co4[1] + co2[4] + co3[2] + co1[3];
        per[21] = co4[1] + co2[3] + co3[2] + co1[4];
        per[22] = co4[1] + co2[2] + co3[3] + co1[4];
        per[23] = co4[1] + co2[4] + co3[3] + co1[2];
        per[24] = co4[1] + co2[3] + co3[4] + co1[2];
        int ans = Integer.MAX_VALUE;
        for(int i=1;i<=24;i++)
        {
            if(per[i] < ans)
                ans = per[i];
        }
        System.out.println(ans);
    }
}