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.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
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;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task3 solver = new Task3();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task3 {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int t = in.nextInt();
            char[][][] rr = new char[4][t][];
            for (int s = 0; s < 4; s++) {
                for (int f = 0; f < t; f++) {
                    rr[s][f] = in.next().toCharArray();
                }
            }
            char[][] nn1 = new char[2 * t][2 * t];
            char[][] nn2 = new char[2 * t][2 * t];
            for (int l = 0; l < 2 * t; l++) {
                for (int r = 0; r < 2 * t; r++) {
                    if ((l + r) % 2 == 0) {
                        nn1[l][r] = '0';
                        nn2[l][r] = '1';
                    } else {
                        nn1[l][r] = '1';
                        nn2[l][r] = '0';
                    }
                }
            }

            Permutations permutations = new Permutations(4);
            int tt = 4 * t * t;
            do {
                char[][][] cur = new char[4][][];
                for (int i = 0; i < 4; i++) {
                    cur[i] = rr[permutations.get()[i]];
                }
                tt = Math.min(tt, ct(cur, nn1));
                tt = Math.min(tt, ct(cur, nn2));

            } while (permutations.next());
            out.println(tt);

        }

        private int ct(char[][][] cur, char[][] nn2) {
            int tt = 0;
            for (int s = 0; s < nn2.length; s++) {
                for (int t = 0; t < nn2.length; t++) {
                    int i = 0;
                    if (s * 2 >= nn2.length) {
                        i += 2;
                    }
                    if (t * 2 >= nn2.length) {
                        i += 1;
                    }
                    if (cur[i][s % (nn2.length / 2)][t % (nn2.length / 2)] != nn2[s][t]) {
                        tt++;
                    }
                }
            }

            return tt;
        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }

    static class Permutations {
        private final int length;
        private long max;
        private long num;
        private int[] data;

        public Permutations(int length) {
            this.data = new int[length];
            Arrays.setAll(data, k -> k);
            this.length = length;
            max = 1;
            for (int t = 1; t < length; t++) {
                max *= t + 1;
            }
        }

        public int[] get() {
            return data;
        }

        public boolean next() {
            num++;
            if (num == max) return false;
            int r = length - 2;
            for (; r >= 0 && data[r] >= data[r + 1]; r--) ;
            int min = r + 1;
            for (int x = r + 2; x < length; x++) {
                if (data[x] > data[r] && data[min] > data[x]) min = x;
            }
            int l = data[min];
            data[min] = data[r];
            data[r] = l;
            Arrays.sort(data, r + 1, data.length);
            return true;
        }

    }
}

