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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

/**
 * todo
 *
 * @author hemenghai
 * @date 2019/1/23 18:50
 */
public class Main {

    private static int cur, pos, sum, len;
    private static int max, min, ans, res;
    private static int ai, bi, ci, di;
    private static int[] aix, bix;
    private static long al, bl, cl, dl;
    private static long[] alx, blx;
    private static double ad, bd, cd, dd;
    private static double[] adx, bdx;
    private static boolean ab, bb, cb, db;
    private static boolean[] abx, bbx;
    private static boolean[][] abxx, bbxx;
    private static char ac, bc, cc, dc;
    private static char[] acx, bcx;
    private static char[][] acxx, bcxx;
    private static String as, bs, cs, ds;
    private static String[] asx, bsx;
    private static InputReader in = new InputReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        len = in.nextInt();
        aix = new int[4];
        bix = new int[4];
        acxx = new char[len][];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < len; j++) {
                as = in.next();
                acxx[j] = as.toCharArray();
            }
            aix[i] = toA();
            bix[i] = toB();
        }
        solve();
        System.out.println(ans);
    }

    private static void solve() {
        ans = Integer.MAX_VALUE;
        dfs(0, 2, 2, 0);
    }

    private static void dfs(int p, int a, int b, int v) {
        if (p == 4) {
            ans = Math.min(v, ans);
            return;
        }
        if (a > 0) {
            dfs(p + 1, a - 1, b, v + aix[p]);
        }
        if (b > 0) {
            dfs(p + 1, a, b - 1, v + bix[p]);
        }
    }

    private static int toB() {
        return toX('1', '0');
    }

    private static int toA() {
        return toX('0', '1');
    }

    private static int toX(char even, char odd) {
        int diff = 0;
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len; j++) {
                if ((i + j) % 2 == 0) {
                    if (acxx[i][j] != even) {
                        diff++;
                    }
                } else {
                    if (acxx[i][j] != odd) {
                        diff++;
                    }
                }
            }
        }
        return diff;
    }

    private static class InputReader {

        private static final char MINUS = '-';
        private static final char POINT = '.';
        private static final char ZERO = '0';

        private InputStream stream;

        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public String next() {
            return readString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == MINUS) {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - ZERO;
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == MINUS) {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != POINT) {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                res *= 10;
                res += c - ZERO;
                c = read();
            }
            if (c == POINT) {
                c = read();
                double m = 1.0D;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    m /= 10;
                    res += (c - ZERO) * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }
    }
}