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

public class Chessboard 
{
	static class C implements Comparator<Integer>
	{

		@Override
		public int compare(Integer arg0, Integer arg1) 
		{
			return Long.signum(delta[arg0] - delta[arg1]);
		}
		
	}
	
	static void ayy(String s, int i, int j, boolean right)
	{
		long k = Long.parseLong(s, 2);
		
		if(j%2 == 0)
		{
			if(!right)
			{
				alpha[i] += countbits(k^bar1);
				beta[i] += countbits(k^bar2);
			}
			else
			{
				alpha[i] += countbits(k^bar3);
				beta[i] += countbits(k^bar4);
			}
//					System.out.println("Comparing with " + Integer.toBinaryString(bar1));
		}
		else
		{
			if(!right)
			{
				alpha[i] += countbits(k^bar2);
				beta[i] += countbits(k^bar1);
			}
			else
			{
				alpha[i] += countbits(k^bar4);
				beta[i] += countbits(k^bar3);
			}
//					System.out.println("Comparing with " + Integer.toBinaryString(bar2));
		}

	}
	
	static long countbits(long i)
	{
		long count = 0;
		
		while(i > 0)
		{
			i = i&(i-1);
			count++;
		}
		
		return count;
	}
	static int n;
	static long[] alpha;
	static long[] beta;
	static long[] delta;
	static long bar1 = 0;
	static long bar2 = 0;
	static long bar3 = 0;
	static long bar4 = 0;
	static int CUTOFF = 50;

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		
		long adder = 1;
		long adder2 = 1;
		for(int i = 0; i < Math.min(n, CUTOFF); i++)
		{
			if(i%2 == 0)
				bar1 += adder;
			else
				bar2 += adder;
			adder *= 2;
		}
		
		int length2 = n - CUTOFF;
		int toggler = (length2)%2;
		if(toggler<0)toggler+=2;
//		System.out.println("Length " + length2);
		
				
		if(n > CUTOFF)
		{
			for(int i = CUTOFF; i < n; i++)
			{
				if(toggler%2 == 0)
					bar3 += adder2;
				else
					bar4 += adder2;
				toggler += 1;
				adder2 *= 2;
			}
		}
//		System.out.println("TOGGLER " + toggler);
//		System.out.println(Long.toBinaryString(bar1));
//		System.out.println(Long.toBinaryString(bar3));
//		System.out.println(Long.toBinaryString(bar2));
//		System.out.println(Long.toBinaryString(bar4));
//		System.out.println(Long.toBinaryString(adder));
		
//		System.out.println(Integer.toBinaryString(bar1));
//		System.out.println(Integer.toBinaryString(bar2));
		
		delta = new long[4];
		alpha = new long[4];
		beta = new long[4];
		Integer[] order = new Integer[4];
		
		for(int i = 0; i < 4; i++)
		{
			order[i] = i;
			for(int j = 0; j < n; j++)
			{
				String s = sc.next();
				
				if(s.length() > CUTOFF)
				{
					String s1 = s.substring(0, CUTOFF);
					String s2 = s.substring(CUTOFF);

					ayy(s1, i, j, false);
					ayy(s2, i, j, true);
				}
				else
				{
					ayy(s, i, j, false);
				}
			}
			delta[i] = beta[i] - alpha[i];
		}
		
		C c = new C();
		Arrays.sort(order, c);
		
		/*
		System.out.println(Arrays.toString(alpha));
		System.out.println(Arrays.toString(beta));
		System.out.println(Arrays.toString(delta));
		System.out.println(Arrays.toString(order));
		*/
		
		int count = 0;
		for(int i = 0; i <= 1; i++)
			count += beta[order[i]];
		for(int i = 2; i <= 3; i++)
			count += alpha[order[i]];
		
		System.out.println(count);
	}

}
