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.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class cf961c {

	static int[] item,perm;
	static boolean[] used;

	static char[][][] map;

	static char[][] aa;
	static char[][] bb;

	static int min;
	static int size;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);



		size = sc.nextInt();

		min = Integer.MAX_VALUE;

		map = new char[4][size][size];

		aa = new char[size*2][size*2];
		bb = new char[size*2][size*2];
		

		for (int d =0 ; d < size*2; d++) {
			int set = d % 2;
			for (int a = 0 ; a < size*2; a++) {
				if (set %2 == 0) {
					aa[d][a] = '0';
					bb[d][a] = '1';
				}else {
					aa[d][a] = '1';
					bb[d][a] = '0';
				}
				set++;
			}
		}

		sc.nextLine();
		for (int i = 0; i < 4; i++) {

			for (int g = 0; g < size; g++) {
				char[] in = sc.nextLine().toCharArray();

				for (int a = 0;  a < size; a++){

					map[i][g][a] = in[a];
				}
			}

			if (i != 3) {
				sc.nextLine();
			}
		}


//		for (int d =0 ; d < size; d++) {
//			System.out.println(Arrays.toString(bb[d]));
//		}

		item = new int[]{0,1,2,3};
		perm = new int[4];
		used = new boolean[4];

		permute(0);

		System.out.println(min);
	}

	public static void permute(int pos) {
		int j = 0;
		if (pos >= used.length) {
			// process current array

			char[][] m = new char[size*2][size*2];

			for (int d =0 ; d < size; d++) {
				for (int a =0 ; a < size; a++) {
					m[d][a] = map[perm[0]][d][a];
				}
			}
			for (int d =0 ; d < size; d++) {
				for (int a =0 ; a < size; a++) {
					m[d][a+size] = map[perm[1]][d][a];
				}
			}
			for (int d =0 ; d < size; d++) {
				for (int a =0 ; a < size; a++) {
					m[d+size][a] = map[perm[2]][d][a];
				}
			}
			for (int d =0 ; d < size; d++) {
				for (int a =0 ; a < size; a++) {
					m[d+size][a+size] = map[perm[3]][d][a];
				}
			}
			//			System.out.println("st\n\n");
			//			for (int d =0 ; d < size*2; d++) {
			//				System.out.println(Arrays.toString(m[d]));
			//			}

			int diffa = 0;
			int diffb = 0;


			for (int d =0 ; d < size*2; d++) {
				for (int a =0 ; a < size*2; a++) {

					if (m[d][a] != aa[d][a]) {
						diffa++;
					}
					if (m[d][a] != bb[d][a]) {
						diffb++;
					}

				}
			}

			min = Math.min(min, Math.min(diffa, diffb));

		}else {
			for (j = 0; j < used.length; j++) {
				if (!used[j]) { 
					used[j] = true;
					perm[pos] = item[j];
					permute(pos+1);
					used[j] = false;
				}
			}
		}
	}

}

/*

3
101
010
101

101
000
101

010
101
011

010
101
010

101010
010101
101010
010101
1010BB
01B1BB


2
11
11

11
11

11
11

00
00

1
0

0

1

0

 */