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

public class A3 {
	static int n;

	static int compare(char[][] x, char[][] y) {
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (x[i][j] != y[i][j]) {
					count++;
				}
			}
		}
		return count;
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		OutputWriter out = new OutputWriter(System.out);
		n = in.readInt();
		long ans = 0;
		char a[][] = new char[n][n];
		char b[][] = new char[n][n];
		char c[][] = new char[n][n];
		char d[][] = new char[n][n];

		char[][] first = new char[n][n];
		char[][] second = new char[n][n];
		int j = 0;
		while (j < n) {
			a[j] = in.readString().toCharArray();
			j++;
		}
		j = 0;
		while (j < n) {
			b[j] = in.readString().toCharArray();
			j++;
		}
		j = 0;
		while (j < n) {
			c[j] = in.readString().toCharArray();
			j++;
		}
		j = 0;
		while (j < n) {
			d[j] = in.readString().toCharArray();
			j++;
		}

		first[0][0] = '0';
		if (n > 1)
			first[1][0] = '1';
		for (j = 1; j < n; j++) {
			if (first[0][j - 1] == '0') {
				first[0][j] = '1';
			} else {
				first[0][j] = '0';
			}
		}
		if (n > 1) {
			for (j = 1; j < n; j++) {
				if (first[1][j - 1] == '0') {
					first[1][j] = '1';
				} else {
					first[1][j] = '0';
				}
			}
		}
		for (int i = 2; i < n; i++) {
			first[i] = first[i - 2];
		}

		for (int i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (first[i][j] == '0') {
					second[i][j] = '1';
				} else {
					second[i][j] = '0';
				}
			}
		}

		// for (int i = 0; i < n; i++) {
		// for (j = 0; j < n; j++) {
		// System.out.print(second[i][j] + " ");
		// }
		// System.out.println();
		// }
		ans = Integer.MAX_VALUE;
		ans = Math.min(ans, compare(a, first) + compare(b, first) + compare(c, second) + compare(d, second));
		ans = Math.min(ans, compare(a, first) + compare(c, first) + compare(b, second) + compare(d, second));
		ans = Math.min(ans, compare(a, first) + compare(d, first) + compare(c, second) + compare(b, second));
		ans = Math.min(ans, compare(c, first) + compare(b, first) + compare(a, second) + compare(d, second));
		ans = Math.min(ans, compare(d, first) + compare(b, first) + compare(c, second) + compare(a, second));
		ans = Math.min(ans, compare(c, first) + compare(d, first) + compare(a, second) + compare(b, second));
		System.out.println(ans);
		out.close();
	}

	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

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

		public 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++];
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			long sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

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

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

	private static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(outputStream);
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}
	}
}