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
def f(M):
    # M is a square matrix

    N = len(M[0])

    cost0 = 0
    cost1 = 0

    #Case 1: M[0][0] = 0
    for i in range(N):
        for j in range(N):
            if (i + j) % 2 == 0:
                if M[i][j] != 0: cost0 += 1
                else: cost1 += 1
            else:
                if M[i][j] != 1: cost0 += 1
                else: cost1 += 1
                
    return (cost0, cost1)

n = int(input())
a, b = [[0 for i in range(n)] for j in range(n)], [[0 for i in range(n)] for j in range(n)]
c, d = [[0 for i in range(n)] for j in range(n)], [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    a[i] = list(map(int, list(input())))
blank = input()
for i in range(n):
    b[i] = list(map(int, list(input())))
blank = input()
for i in range(n):
    c[i] = list(map(int, list(input())))
blank = input()
for i in range(n):
    d[i] = list(map(int, list(input())))

def cost(l):
    s = f(l[0])[0] + f(l[1])[1] + f(l[2])[1] + f(l[3])[0]
    n = len(l[0][0])
    return min(s, 4*n*n - s)

l1 = cost([a,b,c,d])
l2 = cost([a,b,d,c])
l3 = cost([a,c,b,d])
l4 = cost([a,c,d,b])
l5 = cost([a,d,b,c])
l6 = cost([a,d,c,b])
l7 = cost([b,a,c,d])
l8 = cost([b,a,d,c])
l9 = cost([b,c,a,d])
l10 = cost([b,c,d,a])
l11 = cost([b,d,a,c])
l12 = cost([b,d,c,a])
l13 = cost([c,a,b,d])
l14 = cost([c,a,d,b])
l15 = cost([c,b,a,d])
l16 = cost([c,b,d,a])
l17 = cost([c,d,a,b])
l18 = cost([c,d,b,a])
l19 = cost([d,a,b,c])
l20 = cost([d,a,c,b])
l21 = cost([d,b,a,c])
l22 = cost([d,b,c,a])
l23 = cost([d,c,a,b])
l24 = cost([d,c,b,a])

m = min(l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,l16,l17,l18,l19,l20,l21,l22,l23,l24)

print(m)



