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
//package main;

import java.io.*;
import java.util.*;
import java.math.*;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;
    
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    boolean tests = false;
    
    long mod = 1000_000_000 + 7;
    StringBuilder res = new StringBuilder(1000005);
    
    void run() throws Exception {
        int t = tests ? ni() : 1;
        for(int i = 1; i <= t; i++) {
            go(i);
        }
        System.out.print(res.length() == 0 ? "" : res);
    }
    
    void go(int T) throws Exception {
        int n = ni();
        
        char[][] a = new char[n][];
        char[][] b = new char[n][];
        char[][] c = new char[n][];
        char[][] d = new char[n][];
        
        for(int i = 0; i < n; i++) {
            a[i] = nc();
        }
        for(int i = 0; i < n; i++) {
            b[i] = nc();
        }
        for(int i = 0; i < n; i++) {
            c[i] = nc();
        }
        for(int i = 0; i < n; i++) {
            d[i] = nc();
        }
        
        int max = Integer.MAX_VALUE;
        
        char[][][] bds = new char[][][] {a, b, c, d};
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 4; j++) {
                for(int k = 0; k < 4; k++) {
                    for(int l = 0; l < 4; l++) {
                        int[] arr = new int[4];
                        arr[i]++;
                        arr[j]++;
                        arr[k]++;
                        arr[l]++;
                        if(arr[0] == 1 && arr[1] == 1 && arr[2] == 1 && arr[3] == 1) {
                            max = Math.min(max, evaluate(arrange(bds[i], bds[j], bds[k], bds[l])));
                        }
                    }
                }
            }
        }
        
        res.append(max).append("\n");
    }
    
    char[][] arrange(char[][] a, char[][] b, char[][] c, char[][] d) {
        int n = a.length;
        char[][] comp = new char[2 * n][2 * n];
        int row = 0, col = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                comp[row][col++] = a[i][j];
            }
            for(int j = 0; j < n; j++) {
                comp[row][col++] = b[i][j];
            }
            row++; col = 0;
        }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                comp[row][col++] = c[i][j];
            }
            for(int j = 0; j < n; j++) {
                comp[row][col++] = d[i][j];
            }
            row++; col = 0;
        }
        return comp;
    }
    
    int evaluate(char[][] a) {
        int n = a.length;
        char[][] x = new char[n][n];
        char[][] y = new char[n][n];
        x[0][0] = '0';
        y[0][0] = '1';
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(x[i][j] == '0') {
                    continue;
                }
                if(j != 0) {
                    x[i][j] = (x[i][j - 1] == '0') ? '1' : '0';
                } else {
                    x[i][j] = (x[i - 1][j] == '0') ? '1' : '0';
                }
                y[i][j] = (x[i][j] == '0') ? '1' : '0';
            }
        }
        int mx = 0, my = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(x[i][j] != a[i][j]) {
                    mx++;
                }
                if(y[i][j] != a[i][j]) {
                    my++;
                }
            }
        }
        return Math.min(mx, my);
    }
    
    //Reader & Writer
    String nt() throws Exception {
        if (stk == null || !stk.hasMoreTokens())
            stk = new StringTokenizer(br.readLine(), " ");
        if(!stk.hasMoreElements())
            stk = new StringTokenizer(br.readLine(), " ");
        return stk.nextToken();
    }

    char[] nc() throws Exception {
        return nt().toCharArray();
    }

    int ni() throws Exception {
        return Integer.parseInt(nt());
    }

    long nl() throws Exception {
        return Long.parseLong(nt());
    }
    
    double nd() throws Exception {
        return Double.parseDouble(nt());
    }
    
    //Some Misc methods
    int get(int l, int r, int[] a) {
        return l == 0 ? a[r] : a[r] - a[l - 1];
    }
    
    void shuffle(long[] a) {
        Random r = new Random();
        for(int i = 0; i < a.length; i++) {
            int idx = r.nextInt(a.length);
            long temp = a[i];
            a[i] = a[idx];
            a[idx] = temp;
        }
    }
    
    void reverse(long[] a) {
        for(int i = 0, j = a.length - 1; i < j; i++, j--) {
            long temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    }
    
    void print(int[] a) {
        System.out.println(Arrays.toString(a));
    }
    
    void print(long[] a) {
        System.out.println(Arrays.toString(a));
    }
}