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 sys

def solve(io):
  N = io.readInt()

  boards = [ None ] * 4
  for i in range(0, 4):
    boards[i] = io.readStringArray(N)

  best = 1234567890
  for v in [((0, 1), (2, 3)), ((0, 2), (1, 3)), ((0, 3), (1, 2))]:
    best = min(
        best,
        delta(boards[v[0][0]], '0') + delta(boards[v[0][1]], '0') + delta(boards[v[1][0]], '1') + delta(boards[v[1][1]], '1'),
        delta(boards[v[0][0]], '1') + delta(boards[v[0][1]], '1') + delta(boards[v[1][0]], '0') + delta(boards[v[1][1]], '0'),
    )

  io.println(+best)

def delta(b, tl):
  cnt = 0
  for i in range(0, len(b)):
    for j in range(0, len(b[i])):
      if ((i + j) % 2 == 0) != (b[i][j] == tl):
        cnt += 1
  return cnt

# +---------------------+
# | TEMPLATE CODE BELOW |
# |    DO NOT MODIFY    |
# +---------------------+

# TODO: maybe reading byte-by-byte is faster than reading and parsing tokens.
class IO:
  input = None
  output = None
  raw = ""
  buf = []
  pos = 0

  def __init__(self, inputStream, outputStream):
    self.input = inputStream
    self.output = outputStream

  def readToBuffer(self):
    self.raw = self.input.readline().rstrip('\n')
    self.buf = self.raw.split()
    self.pos = 0

  def readString(self):
    while self.pos == len(self.buf):
      self.readToBuffer()
    ans = self.buf[self.pos]
    self.pos += 1
    return ans

  def readInt(self):
    return int(self.readString())

  def readFloat(self):
    return float(self.readString())

  def readStringArray(self, N, offset = 0):
    arr = [ None ] * offset
    for _ in range(0, N):
      arr.append(self.readString())
    return arr

  def readIntArray(self, N, offset = 0):
    arr = [ None ] * offset
    for _ in range(0, N):
      arr.append(self.readInt())
    return arr

  def readFloatArray(self, N, offset = 0):
    arr = [ None ] * offset
    for _ in range(0, N):
      arr.append(self.readFloat())
    return arr

  def readLine(self):
    while self.pos == len(self.buf):
      self.readToBuffer()
    if self.pos > 0:
      raise ValueError("Cannot call readline in the middle of a line.")
    return self.raw

  def prints(self, s):
    self.output.write(str(s))

  def println(self, s):
    self.prints(s)
    self.prints('\n')

  def flushOutput(self):
    self.output.flush()

pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()
