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.*;
public class algo3
{
    static char p1[][];
    static char p2[][];
    static char p3[][];
    static char p4[][];
    static int n;
    public static void main(String args[])
    {
        Scanner ex=new Scanner(System.in);
        n=ex.nextInt();
        p1=new char[n][n];
        p2=new char[n][n];
        p3=new char[n][n];
        p4=new char[n][n];
        for(int i=0;i<n;i++)
        {
            String s=ex.next();
            for(int j=0;j<n;j++)
            p1[i][j]=s.charAt(j);
        }
        for(int i=0;i<n;i++)
        {
            String s=ex.next();
            for(int j=0;j<n;j++)
            p2[i][j]=s.charAt(j);
        }
        for(int i=0;i<n;i++)
        {
            String s=ex.next();
            for(int j=0;j<n;j++)
            p3[i][j]=s.charAt(j);
        }
        for(int i=0;i<n;i++)
        {
            String s=ex.next();
            for(int j=0;j<n;j++)
            p4[i][j]=s.charAt(j);
        }
        int min=4*n*n;
        for(int i=1;i<=4;i++)
        for(int j=1;j<=4;j++)
        for(int k=1;k<=4;k++)
        for(int l=1;l<=4;l++)
        {
            int flag=0;
            for(int a=1;a<=4;a++)
            if(a!=i&&a!=j&&a!=k&&a!=l)
            flag=1;
            if(flag==0)
            {
                min=Math.min(check(i,j,k,l,'0'),min);
                min=Math.min(check(i,j,k,l,'1'),min);
            }
        }
        System.out.println(min);
    }
    public static int check(int a1,int a2,int a3,int a4,char next1)
    {
        char arr1[][]=new char[n][n];
        char arr2[][]=new char[n][n];
        char arr3[][]=new char[n][n];
        char arr4[][]=new char[n][n];
        if(a1==1)
        arr1=p1;
        if(a1==2)
        arr1=p2;
        if(a1==3)
        arr1=p3;
        if(a1==4)
        arr1=p4;
        
        if(a2==1)
        arr2=p1;
        if(a2==2)
        arr2=p2;
        if(a2==3)
        arr2=p3;
        if(a2==4)
        arr2=p4;
        
        if(a3==1)
        arr3=p1;
        if(a3==2)
        arr3=p2;
        if(a3==3)
        arr3=p3;
        if(a3==4)
        arr3=p4;
        
        if(a4==1)
        arr4=p1;
        if(a4==2)
        arr4=p2;
        if(a4==3)
        arr4=p3;
        if(a4==4)
        arr4=p4;
        
        char next=next1;
        int count1=0;
        for(int i=0;i<n;i++)
        {
            next=next1;
            for(int j=0;j<n;j++)
            {
                if(arr1[i][j]!=next)
                count1++;
                if(next=='1')
                next='0';
                else
                next='1';
            }
            for(int j=0;j<n;j++)
            {
                if(arr2[i][j]!=next)
                count1++;
                if(next=='1')
                next='0';
                else
                next='1';
            }
            if(next1=='1')
            next1='0';
            else
            next1='1';
        }
        for(int i=0;i<n;i++)
        {
            next=next1;
            for(int j=0;j<n;j++)
            {
                if(arr3[i][j]!=next)
                count1++;
                if(next=='1')
                next='0';
                else
                next='1';
            }
            for(int j=0;j<n;j++)
            {
                if(arr4[i][j]!=next)
                count1++;
                if(next=='1')
                next='0';
                else
                next='1';
            }
            if(next1=='1')
            next1='0';
            else
            next1='1';
        }
        return count1;
    }
}