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;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long nCr(long long n, long long r) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1];
  return C[r];
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  long long m = sqrt(n);
  for (long long i = 3; i <= m; i += 2)
    if (n % i == 0) return false;
  return true;
}
long long M(long long a) { return (a % (1000000007LL)); }
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<vector<int> > > piece(
      4, vector<vector<int> >(n, vector<int>(n, 0)));
  vector<vector<int> > actual1(2 * n, vector<int>(2 * n, 0));
  vector<vector<int> > actual2(2 * n, vector<int>(2 * n, 0));
  for (long long i = 0; i < (long long)(2 * n); ++i)
    for (long long j = 0; j < (long long)(2 * n); ++j) {
      if ((i + j) & 1)
        actual1[i][j] = 0;
      else
        actual1[i][j] = 1;
    }
  for (long long i = 0; i < (long long)(2 * n); ++i)
    for (long long j = 0; j < (long long)(2 * n); ++j) {
      if ((i + j) & 1)
        actual2[i][j] = 1;
      else
        actual2[i][j] = 0;
    }
  char c;
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[0][i][j] = (int)(c - '0');
    }
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[1][i][j] = (int)(c - '0');
    }
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[2][i][j] = (int)(c - '0');
    }
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[3][i][j] = (int)(c - '0');
    }
  string pat = "ABCD";
  int ans = (1000000007LL);
  do {
    int change1 = 0, change2 = 0;
    for (long long i = 0; i < (long long)(4); ++i) {
      for (long long j = 0; j < (long long)(n); ++j)
        for (long long k = 0; k < (long long)(n); ++k) {
          if (i == 0) {
            if (actual1[j][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          } else if (i == 1) {
            if (actual1[j][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          } else if (i == 2) {
            if (actual1[j + n][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          } else if (i == 3) {
            if (actual1[j + n][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          }
        }
    }
    for (long long i = 0; i < (long long)(4); ++i) {
      for (long long j = 0; j < (long long)(n); ++j)
        for (long long k = 0; k < (long long)(n); ++k) {
          if (i == 0) {
            if (actual2[j][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          } else if (i == 1) {
            if (actual2[j][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          } else if (i == 2) {
            if (actual2[j + n][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          } else if (i == 3) {
            if (actual2[j + n][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          }
        }
    }
    ans = min(ans, min(change1, change2));
  } while (next_permutation(begin(pat), end(pat)));
  cout << ans;
  return 0;
}
