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.io.BufferedInputStream;
import java.util.List;
import java.io.FilterInputStream;
import java.util.Collections;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemCChessboard solver = new ProblemCChessboard();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemCChessboard {
        public static boolean nextPerm(List<Integer> a) {
            int i = a.size() - 2;
            while (i >= 0 && a.get(i) >= a.get(i + 1))
                i--;

            if (i < 0)
                return false;

            int j = a.size() - 1;
            while (a.get(i) >= a.get(j))
                j--;

            Collections.swap(a, i, j);
            Collections.reverse(a.subList(i + 1, a.size()));
            return true;
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();

            String[][] str = new String[4][n];
            int[][] min = new int[4][2];
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < n; j++) str[i][j] = in.scanString();
            }
            for (int i = 0; i < 4; i++) {
                int black_start = 0;
                int white_start = 0;
                for (int j = 0; j < n; j++) {
                    for (int k = 0; k < n; k++) {
                        if ((j + k) % 2 == 0 && str[i][j].charAt(k) == '0') black_start++;
                        if ((j + k) % 2 == 1 && str[i][j].charAt(k) == '1') black_start++;
                        if ((j + k) % 2 == 0 && str[i][j].charAt(k) == '1') white_start++;
                        if ((j + k) % 2 == 1 && str[i][j].charAt(k) == '0') white_start++;
                    }
                }
                min[i][0] = white_start;
                min[i][1] = black_start;
            }
            long ans = Long.MAX_VALUE;
            List<Integer> ln = Arrays.asList(new Integer[]{0, 1, 2, 3});
            do {
                ans = Math.min(((long) min[ln.get(0)][1] + min[ln.get(1)][0] + min[ln.get(2)][0] + min[ln.get(3)][1]), ans);
                ans = Math.min(((long) min[ln.get(0)][0] + min[ln.get(1)][1] + min[ln.get(2)][1] + min[ln.get(3)][0]), ans);
            } while (nextPerm(ln));
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        public String scanString() {
            int c = scan();
            if (c == -1) return null;
            while (isWhiteSpace(c)) c = scan();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = scan();
            } while (!isWhiteSpace(c));
            return res.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

