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.math.*;
import java.awt.geom.*;
public class ChessBoard{
    public static void fill(int[][] a, int n, MyScanner sc){
      for(int i=0;i<n;i++){
        String s=sc.next();
        for(int j=0;j<n;j++)
          a[i][j]=s.charAt(j)-'0';
      }
    }
    public static int layer1(int[][] a, int[][] b, int[][] c, int[][] d, int n){
        int[] t=new int[6];
        t[0]=layer2(a,b,c,d,n);
        t[1]=layer2(a,b,d,c,n);
        t[2]=layer2(a,c,b,d,n);
        t[3]=layer2(a,c,d,b,n);
        t[4]=layer2(a,d,b,c,n);
        t[5]=layer2(a,d,c,b,n);
        int m=Integer.MAX_VALUE;
        for(int i=0; i<6; i++) {
            m=Math.min(m, t[i]);
        }
      return m;
    }
    public static int layer2(int[][] a, int[][] b, int[][] c, int[][] d, int n){
            return need(formboard(a,b,c,d,n));
        }
    public static int[][] formboard(int[][] a, int[][] b, int[][] c, int[][] d, int n){
        int[][] g=new int[2*n][2*n];
        for (int i=0;i<n;i++){
            for (int j=0; j<n; j++){
                g[i][j] = a[i][j];
            }
        }
        for (int i=0; i<n; i++){
            for (int j=0; j<n; j++){
                g[i+n][j]=b[i][j];
            }
        }
        for (int i=0; i<n; i++){
            for (int j=0; j<n; j++){
                g[i][j+n]=c[i][j];
            }
        }
        for (int i=0; i<n; i++){
            for (int j=0; j<n; j++){
                g[i+n][j+n]=d[i][j];
            }
        }
        return g;
    }
    public static int need(int[][] g){
            int p1=0, p2=0;
            for (int i=0; i<g.length; i++){
                for (int j=0; j<g.length; j++){
                    if (g[i][j] == (i+j)%2){
                        p1++;
                    } else{
                        p2++;
                    }
                }
            }
            return Math.min(p1, p2);
        }

    public static void main(String[] args) {
      MyScanner sc=new MyScanner();
      int n=sc.ni();
      int[][] a=new int[n][n];
      int[][] b=new int[n][n];
      int[][] c=new int[n][n];
      int[][] d=new int[n][n];
      fill(a,n,sc);
      fill(b,n,sc);
      fill(c,n,sc);
      fill(d,n,sc);
      int ans=Integer.MAX_VALUE;
      ans=Math.min(ans,layer1(a,b,c,d,n));
      ans=Math.min(ans,layer1(b,a,c,d,n));
      ans=Math.min(ans,layer1(c,b,a,d,n));
      ans=Math.min(ans,layer1(d,b,c,a,n));
      System.out.println(ans);
  }
    private static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int ni() {
          return Integer.parseInt(next());
      }
      float nf() {
        return Float.parseFloat(next());
      }
      long nl() {
          return Long.parseLong(next());
      }

      double nd() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}