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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class experiment
{

    static int M = 1_000_000_007;
    static int INF = 2_000_000_000;
    static final FastScanner fs = new FastScanner();

    //variable

    public static void main(String[] args) throws IOException {

        int n = fs.nextInt();
        int[][] methods = new int[4][2];
        int[][] one = new int[n][n];
        int[][] two = new int[n][n];
        int[][] three = new int[n][n];
        int[][] four = new int[n][n];

        for(int i=0;i<n;i++) {
            String s = fs.next();
            for(int j=0;j<n;j++){
                one[i][j] = s.charAt(j)-'0';
            }
        }
        for(int i=0;i<n;i++) {
            String s = fs.next();
            for(int j=0;j<n;j++){
                two[i][j] = s.charAt(j)-'0';
            }
        }
        for(int i=0;i<n;i++) {
            String s = fs.next();
            for(int j=0;j<n;j++){
                three[i][j] = s.charAt(j)-'0';
            }
        }
        for(int i=0;i<n;i++) {
            String s = fs.next();
            for(int j=0;j<n;j++){
                four[i][j] = s.charAt(j)-'0';
            }
        }
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++){
                if((i+j)%2 != one[i][j]) methods[0][0]++;
                if((i+j+1)%2 != one[i][j]) methods[0][1]++;
            }
        }
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++){
                if((i+j)%2 != two[i][j]) methods[1][0]++;
                if((i+j+1)%2 != two[i][j]) methods[1][1]++;
            }
        }
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++){
                if((i+j)%2 != three[i][j]) methods[2][0]++;
                if((i+j+1)%2 != three[i][j]) methods[2][1]++;
            }
        }
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++){
                if((i+j)%2 != four[i][j]) methods[3][0]++;
                if((i+j+1)%2 != four[i][j]) methods[3][1]++;
            }
        }
        int ans = INF;
//        for(int i=0;i<4;i++) {
//            System.out.println(methods[i][0]+" "+methods[i][1]);
//        }
        for(int i=0;i<4;i++) {
            for(int j=i+1;j<4;j++) {
                int cur = methods[i][0]+methods[j][0];
                for(int k=0;k<4;k++) {
                    if(k==i || k==j) continue;
                    cur += methods[k][1];
                }
               // System.out.println(cur);
                ans = Math.min(cur,ans);
            }
        }
        System.out.println(ans);
    }
    //function


    static int lcm(int x,int y) {
        return (x / gcd(x,y) * y);
    }
    static int gcd(int x, int y) {
        if(x == 0) return y;

        return gcd(y%x,x);
    }
    static void premutation(int n, ArrayList<Integer> arr,boolean[] chosen) {
        if(arr.size() == n) {

        }else {
            for(int i=1; i<=n; i++) {
                if(chosen[i]) continue;
                arr.add(i);
                chosen[i] = true;
                premutation(n,arr,chosen);
                arr.remove(new Integer(i));
                chosen[i] = false;
            }
        }
    }
    static boolean isPalindrome(char[] c) {
        int n = c.length;
        for(int i=0; i<n/2; i++) {
            if(c[i] != c[n-i-1]) return false;
        }
        return true;
    }
    // Template
    static long nCk(int n, int k) {
        return (modMult(fact(n),fastexp(modMult(fact(n-k),fact(k)),M-2)));
    }

    static long fact (long n) {

        long fact =1;
        for(int i=1; i<=n; i++) {
            fact = modMult(fact,i);
        }
        return fact%M;
    }

    static int modMult(long a,long b) {
        return (int) (a*b%M);
    }

    static long fastexp(long x, int y){
        if(y==1) return x;

        long ans = fastexp(x,y/2);
        if(y%2 == 0) return modMult(ans,ans);

        return modMult(ans,modMult(ans,x));
    }

    static final Random random = new Random();

    static void ruffleSort(int arr[])
    {
        int n = arr.length;
        for(int i=0; i<n; i++)
        {
            int j = random.nextInt(n),temp = arr[j];
            arr[j] = arr[i];
            arr[i] = temp;
        }
        Arrays.sort(arr);
    }


    public static class Pairs implements Comparable<Pairs>
    {
        int value,index;
        Pairs(int value, int index) {
            this.value = value;
            this.index = index;
        }
        public int compareTo(Pairs p) {
            return Integer.compare(this.value,p.value);
        }
    }
}
class FastScanner
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer str = new StringTokenizer("");

    String next() throws IOException
    {
        while(!str.hasMoreTokens())
            str = new StringTokenizer(br.readLine());

        return str.nextToken();
    }

    char nextChar() throws IOException {
        return next().charAt(0);
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    float nextfloat() throws IOException
    {
        return Float.parseFloat(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }
    byte nextByte() throws IOException
    {
        return Byte.parseByte(next());
    }
    int [] arrayIn(int n) throws IOException
    {
        int  arr[] = new int[n];
        for(int i=0; i<n; i++)
        {
            arr[i] = nextInt();
        }
        return arr;
    }
}
