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.*;
import java.text.*;

public class Main2{
    final long IINF = (long)1e12, mod = (long)1e9+7;
    DecimalFormat df = new DecimalFormat("0.0000000000");
    final double EPS = 1e-8;
    final int MAX = (int)2e5+5;
    FastReader in;
    PrintWriter out;
    boolean multipleTC = false;
    public static void main(String[] args) throws Exception{
        new Thread(null, new Runnable() {
            public void run(){
                try{new Main2().run();}catch(Exception e){e.printStackTrace();}
            }
        }, "1", 1 << 26).start();
    }
    
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        for(int i = 1, t = (multipleTC)?ni():1; i<=t; i++)solve(i);
        out.flush();    
        out.close();
    }
    
    void solve(int tc) throws Exception{
        int n = ni();
        boolean[][][] b = new boolean[4][n][n];
        for(int k = 0; k< 4; k++){
            for(int i = 0; i< n; i++){
                String s = n();
                while(s.isEmpty())s = n();
                for(int j = 0; j< n; j++)b[k][i][j] = s.charAt(j)=='1';
            }
        }
//        pn(build(n,b,"0123"));
        pn(permute(n,b,"", "0123"));
    }
    
    int build(int n, boolean[][][] b, String s){
        boolean[][] a = new boolean[n*2][n*2];
        int[] map = new int[4];
        for(int i = 0; i<s.length(); i++)map[i] = s.charAt(i)-'0';
        for(int i = 0; i< 4; i++){
            for(int j = 0; j< n; j++){
                for(int k = 0; k< n; k++){
                    a[(map[i]/2)*n+j][(map[i]%2)*n+k] = b[i][j][k];
                }
            }
        }
        int a1 = 0, a2 = 0;
        for(int i = 0; i< 2*n; i++){
            for(int j = 0; j< 2*n; j++){
                if((i+j)%2==1 && a[i][j])a1++;
                else if((i+j)%2==0 && !a[i][j])a1++;
            }
        }
        for(int i = 0; i< 2*n; i++){
            for(int j = 0; j< 2*n; j++){
                if((i+j)%2==0 && a[i][j])a2++;
                else if((i+j)%2==1 && !a[i][j])a2++;
            }
        }
        return Math.min(a1,a2);
    }
    
    int permute(int n,boolean[][][] b,String pre, String base){
        int ans = (int)1e5;
        if(base.length()==0)ans = build(n,b,pre);
        else for(int i = 0; i< base.length(); i++)ans = Math.min(ans, permute(n,b, pre+base.charAt(i), base.substring(0,i)+base.substring(i+1)));
        return ans;
    }
    
    int[] reverse(int[] a){
        int[] o = new int[a.length];
        for(int i = 0; i< a.length; i++)o[i] = a[a.length-i-1];
        return o;   
    }

    int[] sort(int[] a){
        if(a.length==1)return a;
        int mid = a.length/2;
        int[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));
        for(int i = 0, j = 0, k = 0; i< a.length; i++){
            if(j<b.length && k<c.length){
                if(b[j]<c[k])a[i] = b[j++];
                else a[i] = c[k++];
            }else if(j<b.length)a[i] = b[j++];
            else a[i] = c[k++];
        }
        return a;
    }

    long[] sort(long[] a){
        if(a.length==1)return a;
        int mid = a.length/2;
        long[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));
        for(int i = 0, j = 0, k = 0; i< a.length; i++){
            if(j<b.length && k<c.length){
                if(b[j]<c[k])a[i] = b[j++];
                else a[i] = c[k++];
            }else if(j<b.length)a[i] = b[j++];
            else a[i] = c[k++];
        }
        return a;
    }

    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    int ni() throws Exception{return Integer.parseInt(in.next());}
    long nl() throws Exception{return Long.parseLong(in.next());}
    double nd() throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }
 
        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
}       