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

public class CF961C {

	class Quadrant {
		char[][] grid;
		public Quadrant(char[][] gg) {grid = gg;}
		int length() {return grid.length;}
		char[] row(int i) {return grid[i];};
	}
	
	class ChessBoard {
		int n;
		Quadrant[] q;
		char[][] grid;
		public ChessBoard(Quadrant...qq) {
			q = new Quadrant[] {qq[0], qq[1], qq[2], qq[3]};
			n = qq[0].length() * 2;
			grid = new char[n][n];
			for(int i = 0, j = n / 2 ; i < n / 2 ; i++, j++) {
				grid[i] = (new String(q[0].row(i)) + new String(q[1].row(i))).toCharArray();
				grid[j] = (new String(q[2].row(i)) + new String(q[3].row(i))).toCharArray();
			}
		}
		int minChanges() {
			char[] key1 = new char[n];
			char[] key2 = new char[n];
			for(int i = 0 ; i < n ; i++) {
				if(i % 2 == 0) {
					key1[i] = '0';
					key2[i] = '1';
				} else {
					key1[i] = '1';
					key2[i] = '0';
				}
			}
			int res1 = 0, res2 = 0;
			for(int i = 0 ; i < n ; i++) {
				int t = i % 2;
				for(int j = 0 ; j < n ; j++) {
					if(t == 0) {
						if(grid[i][j] != key1[j])
							res1++;
						if(grid[i][j] != key2[j])
							res2++;
					} else {
						if(grid[i][j] != key2[j])
							res1++;
						if(grid[i][j] != key1[j])
							res2++;
					}
				}
			}
			return Math.min(res1, res2);
		}
		void printGrid() {
			for(int i = 0 ; i < n ; i++)
				System.out.println(new String(grid[i]));
			System.out.println();
		}
	}
	
	final int MOD = (int) 1e9 + 7;
	final double ERROR = 1e-9;
	final double oo = 1e50;

	public CF961C(SuperScanner scan, PrintWriter out) {
		int n = scan.nextInt();
		Quadrant[] a = new Quadrant[4];
		for(int k = 0 ; k < 4 ; k++) {
			char[][] grid = new char[n][n];
			for(int i = 0 ; i < n ; i++)
				grid[i] = scan.next().toCharArray();
			a[k] = new Quadrant(grid);
		}
		System.out.println(permute(new Quadrant[4], a, 0, 0));
	}
	
	int permute(Quadrant[] q, Quadrant[] a, int d, int v) {
		if(d == 4)
			return new ChessBoard(q).minChanges();
		int res = Integer.MAX_VALUE;
		for(int i = 0 ; i < 4 ; i++) {
			if((v & (1 << i)) == 0) {
				q[d] = a[i];
				res = Math.min(res, permute(q, a, d + 1, v | (1 << i)));
			}
		}
		return res;
	}

	static class SuperScanner {
		public int BS = 1 << 16;
		public char NC = (char) 0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public SuperScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public SuperScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar() {
			while (bId == size) {
				try {
					size = in.read(buf);
				} catch (Exception e) {
					return NC;
				}
				if (size == -1)
					return NC;
				bId = 0;
			}
			return (char) buf[bId++];
		}

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

		public long nextLong() {
			num = 1;
			boolean neg = false;
			if (c == NC)
				c = nextChar();
			for (; (c < '0' || c > '9'); c = nextChar()) {
				if (c == '-')
					neg = true;
			}
			long res = 0;
			for (; c >= '0' && c <= '9'; c = nextChar()) {
				res = (res << 3) + (res << 1) + c - '0';
				num *= 10;
			}
			return neg ? -res : res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c != '.' ? cur : cur + nextLong() / num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while (c <= 32)
				c = nextChar();
			while (c > 32) {
				res.append(c);
				c = nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while (c <= 32)
				c = nextChar();
			while (c != '\n') {
				res.append(c);
				c = nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if (c > 32)
				return true;
			while (true) {
				c = nextChar();
				if (c == NC)
					return false;
				else if (c > 32)
					return true;
			}
		}
	}

	public static void main(String[] args) {
		SuperScanner scan = new SuperScanner();
		PrintWriter out = new PrintWriter(System.out);
		new CF961C(scan, out);
		out.close();
	}
}
