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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CChessboard solver = new CChessboard();
        solver.solve(1, in, out);
        out.close();
    }

    static class CChessboard {
        int n;
        int[][][] arr;
        Stack<Integer> st;

        public void readInput(Scanner sc) {
            n = sc.nextInt();
            arr = new int[4][n][n];
            for (int i = 0; i < 4; i++)
                for (int j = 0; j < n; j++) {
                    String s = sc.next();
                    for (int k = 0; k < n; k++)
                        arr[i][j][k] = s.charAt(k) - '0';
                }
        }

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int q = 1;
            while (q-- > 0) {
                readInput(sc);
                st = new Stack<>();
                pw.println(bf(0));
            }
        }

        private int bf(int msk) {
            if (msk == (1 << 4) - 1)
                return construct();
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < 4; i++)
                if ((msk & 1 << i) == 0) {
                    st.add(i);
                    min = Math.min(min, bf(msk | 1 << i));
                    st.pop();
                }
            return min;
        }

        private int construct() {
            int[][] chess = new int[2 * n][2 * n];
            Stack<Integer> temp = (Stack<Integer>) st.clone();
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    chess[i][j] = arr[temp.peek()][i][j];
            temp.pop();
            for (int i = 0; i < n; i++)
                for (int j = n; j < 2 * n; j++)
                    chess[i][j] = arr[temp.peek()][i][j - n];
            temp.pop();
            for (int i = n; i < 2 * n; i++)
                for (int j = 0; j < n; j++)
                    chess[i][j] = arr[temp.peek()][i - n][j];
            temp.pop();
            for (int i = n; i < 2 * n; i++)
                for (int j = n; j < 2 * n; j++)
                    chess[i][j] = arr[temp.peek()][i - n][j - n];
            int sum0 = 0, sum2 = 0;
            for (int i = 0; i < 2 * n; i++)
                for (int j = 0; j < 2 * n; j++) {
                    int cur = (i + j) % 2;
                    int cur2 = cur ^ 1;
                    if (chess[i][j] != cur)
                        sum0++;
                    if (chess[i][j] != cur2)
                        sum2++;
                }
            return Math.min(sum0, sum2);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            try {
                while (st == null || !st.hasMoreTokens())
                    st = new StringTokenizer(br.readLine());
                return st.nextToken();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

