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.*;
import java.util.*;

public class Main {

	public static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			tokenizer = null;
		}

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public Integer[] nextIntegerArr(int n) {
			Integer[] arr = new Integer[n];
			for (int i = 0; i < n; i++) {
				arr[i] = new Integer(this.nextInt());
			}
			return arr;
		}

		public int[][] next2DIntArr(int n, int m) {
			int[][] arr = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					arr[i][j] = this.nextInt();
				}
			}
			return arr;
		}

		public int[] nextSortedIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

		public long[] nextLongArr(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextLong();
			}
			return arr;
		}

		public long[] nextSortedLongArr(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

		public char[] nextCharArr(int n) {
			char[] arr = new char[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextChar();
			}
			return arr;
		}
	}

	public static InputReader scn = new InputReader();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		// InputStream inputStream = System.in; // Useful when taking input other than
		// console eg file handling // check ctor of inputReader
		// To print in file use this:- out = new PrintWriter("destination of file")
		// including extension");

		int n = scn.nextInt();
		
		int[][] a1 =new int[n][n];
		int[][] a2 =new int[n][n];
		int[][] a3 =new int[n][n];
		int[][] a4 =new int[n][n];
		
		for(int i = 0; i < n; i++) {
			char[] arr = scn.next().toCharArray();
			for(int j = 0; j < n; j++) {
				a1[i][j] = arr[j] - '0';
			}
		}
		
		for(int i = 0; i < n; i++) {
			char[] arr = scn.next().toCharArray();
			for(int j = 0; j < n; j++) {
				a2[i][j] = arr[j] - '0';
			}
		}
		
		for(int i = 0; i < n; i++) {
			char[] arr = scn.next().toCharArray();
			for(int j = 0; j < n; j++) {
				a3[i][j] = arr[j] - '0';
			}
		}
		
		for(int i = 0; i < n; i++) {
			char[] arr = scn.next().toCharArray();
			for(int j = 0; j < n; j++) {
				a4[i][j] = arr[j] - '0';
			}
		}
		
		int ans = func(a1, a2, a3, a4, n);
		ans = Math.min(func(a1, a2, a4, a3, n), ans);
		ans = Math.min(func(a1, a3, a2, a4, n), ans);
		ans = Math.min(func(a1, a3, a4, a2, n), ans);
		ans = Math.min(func(a1, a4, a2, a3, n), ans);
		ans = Math.min(func(a1, a4, a3, a2, n), ans);
		
		ans = Math.min(func(a2, a1, a3, a4, n), ans);
		ans = Math.min(func(a2, a1, a4, a3, n), ans);
		ans = Math.min(func(a2, a3, a1, a4, n), ans);
		ans = Math.min(func(a2, a3, a4, a1, n), ans);
		ans = Math.min(func(a2, a4, a1, a3, n), ans);
		ans = Math.min(func(a2, a4, a3, a1, n), ans);
		
		ans = Math.min(func(a3, a1, a2, a4, n), ans);
		ans = Math.min(func(a3, a1, a4, a2, n), ans);
		ans = Math.min(func(a3, a2, a1, a4, n), ans);
		ans = Math.min(func(a3, a2, a4, a1, n), ans);
		ans = Math.min(func(a3, a4, a1, a2, n), ans);
		ans = Math.min(func(a3, a4, a2, a1, n), ans);
		
		ans = Math.min(func(a4, a1, a2, a3, n), ans);
		ans = Math.min(func(a4, a1, a3, a2, n), ans);
		ans = Math.min(func(a4, a2, a1, a3, n), ans);
		ans = Math.min(func(a4, a2, a3, a1, n), ans);
		ans = Math.min(func(a4, a4, a1, a3, n), ans);
		ans = Math.min(func(a4, a4, a3, a1, n), ans);
		
		System.out.println(ans);
	}
	
	public static int func(int[][] a1, int[][] a2, int[][] a3, int[][] a4, int n) {
		int rv = 0;
		
		int[][] arr1 = new int[2 * n][2 * n], arr2 = new int[2 * n][2 * n];
		
		for(int i = 0; i < 2 * n; i++) {
			for(int j = 0; j < 2 * n; j++) {
				if((i + j) % 2 == 0) {
					arr1[i][j] = 1;
					arr2[i][j] = 0;
				} else {
					arr1[i][j] = 0;
					arr2[i][j] = 1;
				}
			}
		}
		
		int x = 0, y = 0;
		
		for(int i = 0; i < 2 * n; i++) {
			for(int j = 0; j < 2 * n; j++) {
				if(i < n && j  < n) {
					if(a1[i][j] != arr1[i][j]) {
						x++;
					}
					if(a1[i][j] != arr2[i][j]) {
						y++;
					}
				} else if(i < n && j >= n) {
					if(a2[i][j - n] != arr1[i][j]) {
						x++;
					}
					if(a2[i][j - n] != arr2[i][j]) {
						y++;
					}
				} else if(i >= n && j < n) {
					if(a3[i - n][j] != arr1[i][j]) {
						x++;
					}
					if(a3[i - n][j] != arr2[i][j]) {
						y++;
					}
				} else if(i >= n&& j >= n) {
					if(a4[i - n][j - n] != arr1[i][j]) {
						x++;
					}
					if(a4[i - n][j - n] != arr2[i][j]) {
						y++;
					}
				} else {
					System.out.println(0 / 0);
				}
			}
		}

		rv = Math.min(x, y);
		
		return rv;
	}
}