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.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String[] s1 = new String[n];
            for (int i = 0; i < n; i++) {
                s1[i] = in.next();
            }
            in.nextLine();
            String[] s2 = new String[n];
            for (int i = 0; i < n; i++) {
                s2[i] = in.next();
            }
            in.nextLine();
            String[] s3 = new String[n];
            for (int i = 0; i < n; i++) {
                s3[i] = in.next();
            }
            in.nextLine();
            String[] s4 = new String[n];
            for (int i = 0; i < n; i++) {
                s4[i] = in.next();
            }
            long minP = n * n * 4;
            minP = Math.min(minP, paint(s1, s2, s3, s4, n));
            minP = Math.min(minP, paint(s1, s2, s4, s3, n));
            minP = Math.min(minP, paint(s1, s3, s2, s4, n));
            minP = Math.min(minP, paint(s1, s3, s4, s2, n));
            minP = Math.min(minP, paint(s1, s4, s2, s3, n));
            minP = Math.min(minP, paint(s1, s4, s3, s2, n));
            minP = Math.min(minP, paint(s2, s1, s3, s4, n));
            minP = Math.min(minP, paint(s2, s1, s4, s3, n));
            minP = Math.min(minP, paint(s2, s3, s1, s4, n));
            minP = Math.min(minP, paint(s2, s3, s4, s1, n));
            minP = Math.min(minP, paint(s2, s4, s1, s3, n));
            minP = Math.min(minP, paint(s2, s4, s3, s1, n));
            minP = Math.min(minP, paint(s3, s1, s2, s4, n));
            minP = Math.min(minP, paint(s3, s1, s4, s2, n));
            minP = Math.min(minP, paint(s3, s2, s1, s4, n));
            minP = Math.min(minP, paint(s3, s2, s4, s1, n));
            minP = Math.min(minP, paint(s3, s4, s1, s2, n));
            minP = Math.min(minP, paint(s3, s4, s2, s1, n));
            minP = Math.min(minP, paint(s4, s1, s2, s3, n));
            minP = Math.min(minP, paint(s4, s1, s3, s2, n));
            minP = Math.min(minP, paint(s4, s2, s1, s3, n));
            minP = Math.min(minP, paint(s4, s2, s3, s1, n));
            minP = Math.min(minP, paint(s4, s3, s1, s2, n));
            minP = Math.min(minP, paint(s4, s3, s2, s1, n));
            out.println(minP);
        }

        long paint(String[] s1, String[] s2, String[] s3, String[] s4, int n) {
            String[] d1234 = new String[2 * n];
            for (int i = 0; i < n; i++) {
                d1234[i] = s1[i] + s2[i];
            }
            for (int i = n; i < 2 * n; i++) {
                d1234[i] = s3[i - n] + s4[i - n];
            }
            long v1 = 0;
            long v2 = 0;
            for (int i = 0; i < 2 * n; i++) {
                for (int j = 0; j < 2 * n; j++) {
                    if ((j + i) % 2 == 1) {
                        if (d1234[i].charAt(j) == '0') v1++;
                        if (d1234[i].charAt(j) == '1') v2++;
                    } else if ((j + i) % 2 == 0) {
                        if (d1234[i].charAt(j) == '1') v1++;
                        if (d1234[i].charAt(j) == '0') v2++;
                    }
                }
            }
            return Math.min(v1, v2);
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

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

    }
}

