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.Scanner;
public class c961 {
	static int getCntDiff(int startVal) {
		int res=0;
		int val=startVal;
		for(int x=0; x<2*n; x++) {
			for(int y=0; y<2*n; y++) {
				if(b[x][y]!=val) {
					res+=1;
				}
				if(val==0) {
					val=1;
				} else {
					val=0;
				}
			}
			if(val==0) {
				val=1;
			} else {
				val=0;
			}			
		}
		return res;
	}
	static int check(int x, int y) {
		int cntR=0;
		int cntW=0;
		if(x>0) {
		   if (b[x-1][y]!=b[x][y]) {
		      cntR+=1;
		   } else {
			  cntW+=1;			   
		   }
		}
		if (x<2*n-1) {
		   if (b[x+1][y]!=b[x][y]) {
			  cntR+=1;
		   } else {
			  cntW+=1;			   
		   }
		}
		if (y>0) {
		   if (b[x][y-1]!=b[x][y]) {
				cntR+=1;
		   } else {
				cntW+=1;			   
		   }
		}
		if (y<2*n-1) {
			if (b[x][y+1]!=b[x][y]) {
				cntR+=1;
			} else {
				cntW+=1;
			}
		}
		if (cntR>cntW) {
			return 1;
		} else if (cntR<cntW) {
			return -1;
		} else {
			return 0;
		}
	}				
	static void fill(int i,int x0, int y0) {
		mb[x0][y0]=1;
		for(int x=x0*n; x<x0*n+n;x++) {
			for(int y=y0*n; y<y0*n+n; y++) {
				b[x][y]=a[i][x-x0*n][y-y0*n];
			}
		}		
	}
	static int[][][] a;
	static int[][] b;
	static int[][] mb=new int[2][2];
	static int n;
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a=new int[4][n][n];
		for(int i=0; i<4; i++) {
			for(int x=0; x<n;x++) {
				char[] s=sc.next().toCharArray();
				for(int y=0;y<n; y++) {
					a[i][x][y]=s[y]-48;
				}
			}
		}		
		int minCntDiff=2*n*2*n;			
		for(int x1=0;x1<2;x1++) {
			for(int y1=0;y1<2;y1++) {
				for(int x2=0; x2<2; x2++) {
					for(int y2=0; y2<2; y2++) {
						for(int x3=0; x3<2; x3++) {
							for(int y3=0; y3<2; y3++) {
								if(x1==x2 && y1==y2) {
									continue;
								}
								if(x1==x3 && y1==y3) {
									continue;
								}
								if(x2==x3 && y2==y3) {
									continue;
								}
								b= new int[2*n][2*n];
								fill(0,x1,y1);
								fill(1,x2,y2);
								fill(2,x3,y3);
								boolean changed;
								for(int x4=0; x4<2;x4++) {
									for(int y4=0; y4<2; y4++) {
										if(mb[x4][y4]==0) {
											fill(3,x4,y4);
										}
									}
								}
								
								int[][] b0;
								b0 = new int[2*n][];
								for(int i=0;i<2*n;i++) {
									b0[i]=b[i].clone();
								}
								int step=0;
								/*
								!!!
								System.out.println("Step "+ step);
								for(int x=0; x<2*n;x++) {												
									for(int y=0; y<2*n;y++) {
										System.out.print(b[x][y]);
									}
									System.out.println("");
								}
								!!!
								do {
									changed=false;											
												for (int x=0; x<2*n; x++) {
													for(int y=0; y<2*n; y++) {
														if (check(x, y)<0) {
															changed = true;
															if (b[x][y]==1) {
																b[x][y]=0;															
															} else {
																b[x][y]=1;														
															}
														}
													}										
											}
											step+=1;
											!!!
											System.out.println("Step "+ step);
											
											for(int x=0; x<2*n;x++) {												
												for(int y=0; y<2*n;y++) {
													System.out.print(b[x][y]);
												}
												System.out.println("");
											}
											!!!
								} while(changed);
								*/
								int cntDiff0 = getCntDiff(0);
								int cntDiff1 = getCntDiff(1);								
								
								if (cntDiff0<minCntDiff) {
									minCntDiff=cntDiff0;
								}
								if (cntDiff1<minCntDiff) {
									minCntDiff=cntDiff1;
								}								
								mb=new int[2][2];
								break;
						}
					}
				}				
			}
		}		
	}
	System.out.println(minCntDiff);	
}
}	
