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.ArrayList;
import java.util.Scanner;

public final class ChessBoardCF {
    public static  int min=Integer.MAX_VALUE;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int first[][]=new int[n][n];
        int second[][]=new int[n][n];
        int third[][]=new int[n][n];
        int fourth[][]=new int[n][n];



        for(int i=0;i<n;i++){
            String s=sc.next();
            for(int j=0;j<n;j++){
                first[i][j]=Integer.parseInt(s.charAt(j)+"");
            }
        }
        for(int i=0;i<n;i++){
            String s=sc.next();
            for(int j=0;j<n;j++){
                second[i][j]=Integer.parseInt(s.charAt(j)+"");
            }
        }
        for(int i=0;i<n;i++){
            String s=sc.next();
            for(int j=0;j<n;j++){
                third[i][j]=Integer.parseInt(s.charAt(j)+"");
            }
        }
        for(int i=0;i<n;i++){
            String s=sc.next();
            for(int j=0;j<n;j++){
                fourth[i][j]=Integer.parseInt(s.charAt(j)+"");
            }
        }


        ArrayList<int[][]> l=new ArrayList<>();
        l.add(first);
        l.add(second);
        l.add(third);
        l.add(fourth);


        int arr[]=new int[4];
        for(int i=0;i<4;i++)
            arr[i]=i+1;
        boolean vis[]=new boolean[4];
        int ans[]=new int[4];

        helper(l,n,arr,0,vis,ans,0,4);
        System.out.println(min);
    }

    private static void helper(ArrayList<int [][]> l, int n, int[] arr, int start, boolean[] vis, int[] ans, int index, int size) {

        if(start==size){
            helper2(l,n,ans);
            return;
        }

        for(int i=0;i<size;i++){
            if(!vis[i]){
                ans[index]=arr[i];
                vis[i]=true;
                helper(l, n, arr, start+1, vis, ans, index+1, size);
                vis[i]=false;
            }
        }
    }

    private static void helper2(ArrayList<int [][]> l, int n, int[] ans) {

        int first[][]=l.get(ans[0]-1);
        int second[][]=l.get(ans[1]-1);
        int third[][]=l.get(ans[2]-1);
        int fourth[][]=l.get(ans[3]-1);

        int count=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if((i+j)%2==0){
                    if(first[i][j]!=1)
                        count++;
                    if(fourth[i][j]!=1)
                        count++;
                }else{
                    if(first[i][j]!=0)
                        count++;
                    if(fourth[i][j]!=0)
                        count++;
                }
            }
        }


        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if((i+j)%2==0){
                    if(second[i][j]!=0)
                        count++;
                    if(third[i][j]!=0)
                        count++;
                }else{
                    if(second[i][j]!=1)
                        count++;
                    if(third[i][j]!=1)
                        count++;
                }
            }
        }
        min=Math.min(min,count);
    }
}
