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 Hello{
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	Scanner in=new Scanner(System.in);

	int n;
	public void solve(){
		n  = ni();
		char[][] m1 = nm(n, n);
		char[][] m2 = nm(n, n);
		char[][] m3 = nm(n, n);
		char[][] m4 = nm(n, n);

		char[] p = {'1', '2', '3', '4'};
		int ans = first(m1) + first(m3) + second(m2) + second(m4);

		while(next_permutation(p)){
			int res = 0;
			if(p[0] == '1' || p[0] == '3'){
				res += first(m1);
			}
			else{
				res += second(m1);
			}

			if(p[1] == '1' || p[1] == '3'){
				res += first(m2);
			}
			else{
				res += second(m2);
			}

			if(p[2] == '1' || p[2] == '3'){
				res += first(m3);
			}
			else{
				res += second(m3);
			}

			if(p[3] == '1' || p[3] == '3'){
				res += first(m4);
			}
			else{
				res += second(m4);
			}

			ans = Math.min(ans, res);
		}
		out.println(ans);
	}
		boolean next_permutation(char[] p) {
		  for (int a = p.length - 2; a >= 0; --a)
		    if (p[a] < p[a + 1])
		      for (int b = p.length - 1;; --b)
		        if (p[b] > p[a]) {
		          char t = p[a];
		          p[a] = p[b];
		          p[b] = t;
		          for (++a, b = p.length - 1; a < b; ++a, --b) {
		            t = p[a];
		            p[a] = p[b];
		            p[b] = t;
		          }
		          return true;
		        }
		  return false;
		}

	int second(char[][] map){
		char[][] req = new char[n][n];
		int cur = 1, ret = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(cur == 0){
					req[i][j] = '0';
				}
				else{
					req[i][j] = '1';
				}

				cur = (cur+1)%2;

				if(map[i][j] != req[i][j])
					ret+=1;
			}
		}

		return ret;	
	}

	int first(char[][] map){
		char[][] req = new char[n][n];
		int cur = 0, ret = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(cur == 0){
					req[i][j] = '0';
				}
				else{
					req[i][j] = '1';
				}

				cur = (cur+1)%2;

				if(map[i][j] != req[i][j])
					ret+=1;
			}
		}

		return ret;
	} 

	void run(){
		is = new DataInputStream(System.in);
		out = new PrintWriter(System.out);
		int t=1;while(t-->0)solve();
		out.flush();
	}
	public static void main(String[] args)throws Exception{new Hello().run();}
	//Fast I/O code is copied from uwi code.
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	private int readByte(){
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	private String ns(){
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	private char[] ns(int n){
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	private char[][] nm(int n, int m){
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	private int[] na(int n){
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	private int ni(){
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	private long nl(){
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	static  int i(long x){return (int)Math.round(x);}
	static int i(double x){return (int)Math.round(x);}
	static class Pair implements Comparable<Pair>{
		long fs,sc;
		Pair(long a,long b){
			fs=a;sc=b;
		}
		public int compareTo(Pair p){
			if(this.fs>p.fs)return 1;
			else if(this.fs<p.fs)return -1;
			else{
				return i(this.sc-p.sc);
			}
			//return i(this.sc-p.sc);
		}
		public String toString(){
			return "("+fs+","+sc+")";
		}	
	}
	
}