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.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Main{
	static FastScanner s=new FastScanner(System.in);

	static StringBuilder diff=new StringBuilder();
	void solve(){
		int n=s.nextInt();
		for(int a=0;a<2;++a)for(int b=0;b<2;++b)
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				diff.append((i+j+a*n+b*n)%2==0?'1':'0');
			}
		}
		String a="",b="",c="",d="";
		for(int i=0;i<n;++i)a+=s.next();
		for(int i=0;i<n;++i)b+=s.next();
		for(int i=0;i<n;++i)c+=s.next();
		for(int i=0;i<n;++i)d+=s.next();
		System.out.println(
				LongStream.of(
						f(a,b,c,d),
						f(a,b,d,c),
						f(a,c,b,d),
						f(a,c,d,b),
						f(a,d,b,c),
						f(a,d,c,b))
				//.peek(System.err::println)
				.min().getAsLong());
	}
	private long f(String a,String b,String c,String d){
		String v=a+b+c+d;
		return Math.min(
				IntStream.range(0,v.length()).filter(i->v.charAt(i)!=diff.charAt(i)).count(),
				IntStream.range(0,v.length()).filter(i->v.charAt(i)==diff.charAt(i)).count()
				);
	}
	public static void main(String[] $){
		new Main().solve();
	}

	int gInt(){
		return s.nextInt();
	}
	long gLong(){
		return s.nextLong();
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class FastScanner{
	private final BufferedInputStream	in;
	private static final int			bufSize	=1<<16;
	private final byte					buf[]	=new byte[bufSize];
	private int							i		=bufSize,k=bufSize;
	private final StringBuilder			str		=new StringBuilder();

	FastScanner(InputStream in){
		this.in=new BufferedInputStream(in,bufSize);
	}
	int nextInt(){
		return (int)nextLong();
	}
	long nextLong(){
		int c;
		long x=0;
		boolean sign=true;
		while((c=nextChar())<=32)
			;
		if(c=='-'){
			sign=false;
			c=nextChar();
		}
		if(c=='+'){
			c=nextChar();
		}
		while(c>='0'){
			x=x*10+(c-'0');
			c=nextChar();
		}
		return sign?x:-x;
	}
	private int nextChar(){
		if(i==k){
			try{
				k=in.read(buf,i=0,bufSize);
			}catch(IOException e){
				System.exit(-1);
			}
		}
		return i>=k?-1:buf[i++];
	}
	String next(){
		int c;
		str.setLength(0);
		while((c=nextChar())<=32&&c!=-1)
			;
		if(c==-1)
			return null;
		while(c>32){
			str.append((char)c);
			c=nextChar();
		}
		return str.toString();
	}
	String nextLine(){
		int c;
		str.setLength(0);
		while((c=nextChar())<=32&&c!=-1)
			;
		if(c==-1)
			return null;
		while(c!='\n'){
			str.append((char)c);
			c=nextChar();
		}
		return str.toString();
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	private int	remain;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.remain=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return remain>0;
	}

	@Override
	public T next(){
		--remain;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	public final int	from,to,d;
	private int			cur;

	Range(int from,int to,int d){
		this.from=from;
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}

	protected final int CHARACTERISTICS=Spliterator.SIZED|Spliterator.DISTINCT|Spliterator.IMMUTABLE|Spliterator.NONNULL;
	@Override
	public Spliterator.OfInt spliterator(){
		return Spliterators.spliterator(this,(to-from)/d+1,CHARACTERISTICS);
	}

	IntStream stream(){
		return d==1?IntStream.rangeClosed(from,to):java.util.stream.StreamSupport.intStream(this.spliterator(),false);
	}


	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(t,f,-1);
	}


}
