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
#include <bits/stdc++.h>
using namespace std;
int a1[200][200], a2[200][200], a3[200][200], a4[200][200];
int n;
int check(int arr[]) {
  int ans = 0;
  int blah[2 * n][2 * n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[0] == 1)
        blah[i][j] = a1[i][j];
      else if (arr[0] == 2)
        blah[i][j] = a2[i][j];
      else if (arr[0] == 3)
        blah[i][j] = a3[i][j];
      else if (arr[0] == 4)
        blah[i][j] = a4[i][j];
    }
  }
  for (int i = n; i < 2 * n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[1] == 1)
        blah[i][j] = a1[i - n][j];
      else if (arr[1] == 2)
        blah[i][j] = a2[i - n][j];
      else if (arr[1] == 3)
        blah[i][j] = a3[i - n][j];
      else if (arr[1] == 4)
        blah[i][j] = a4[i - n][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = n; j < 2 * n; j++) {
      if (arr[2] == 1)
        blah[i][j] = a1[i][j - n];
      else if (arr[2] == 2)
        blah[i][j] = a2[i][j - n];
      else if (arr[2] == 3)
        blah[i][j] = a3[i][j - n];
      else if (arr[2] == 4)
        blah[i][j] = a4[i][j - n];
    }
  }
  for (int i = n; i < 2 * n; i++) {
    for (int j = n; j < 2 * n; j++) {
      if (arr[3] == 1)
        blah[i][j] = a1[i - n][j - n];
      else if (arr[3] == 2)
        blah[i][j] = a2[i - n][j - n];
      else if (arr[3] == 3)
        blah[i][j] = a3[i - n][j - n];
      else if (arr[3] == 4)
        blah[i][j] = a4[i - n][j - n];
    }
  }
  int blah1[2 * n][2 * n];
  for (int i = 0; i < 2 * n; i++) {
    for (int j = 0; j < 2 * n; j++) {
      blah1[i][j] = blah[i][j];
    }
  }
  for (int i = 0; i < 2 * n; i++) {
    if (i != 0 && blah[i][0] == blah[i - 1][0]) {
      blah[i][0] = (blah[i - 1][0] + 1) % 2;
      ans += 1;
    }
    for (int j = 1; j < 2 * n; j++) {
      if (blah[i][j] == blah[i][j - 1]) {
        blah[i][j] = (blah[i][j - 1] + 1) % 2;
        ans += 1;
      }
    }
  }
  int ans1 = 0;
  blah1[0][0] = (blah1[0][0] + 1) % 2;
  ans1 += 1;
  for (int i = 0; i < 2 * n; i++) {
    if (i != 0 && blah1[i][0] == blah1[i - 1][0]) {
      blah1[i][0] = (blah1[i - 1][0] + 1) % 2;
      ans1 += 1;
    }
    for (int j = 1; j < 2 * n; j++) {
      if (blah1[i][j] == blah1[i][j - 1]) {
        blah1[i][j] = (blah1[i][j - 1] + 1) % 2;
        ans1 += 1;
      }
    }
  }
  return min(ans, ans1);
}
int main() {
  cin >> n;
  char x;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> x;
      if (x == '0')
        a1[i][j] = 0;
      else
        a1[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> x;
      if (x == '0')
        a2[i][j] = 0;
      else
        a2[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> x;
      if (x == '0')
        a3[i][j] = 0;
      else
        a3[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> x;
      if (x == '0')
        a4[i][j] = 0;
      else
        a4[i][j] = 1;
    }
  }
  int arr[] = {1, 2, 3, 4};
  int ans = 1e6;
  do {
    ans = min(ans, check(arr));
  } while (next_permutation(arr, arr + 4));
  cout << ans << endl;
}
