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 int A[105][105];
long long int B[105][105];
long long int C[105][105];
long long int D[105][105];
long long int n;
long long int Acost(long long int nn) {
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      if ((i + j) % 2 == 0 && A[i][j] != nn) sum++;
      if ((i + j) % 2 != 0 && A[i][j] == nn) sum++;
    }
  }
  return sum;
}
long long int Bcost(long long int nn) {
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      if ((i + j) % 2 == 0 && B[i][j] != nn) sum++;
      if ((i + j) % 2 != 0 && B[i][j] == nn) sum++;
    }
  }
  return sum;
}
long long int Ccost(long long int nn) {
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      if ((i + j) % 2 == 0 && C[i][j] != nn) sum++;
      if ((i + j) % 2 != 0 && C[i][j] == nn) sum++;
    }
  }
  return sum;
}
long long int Dcost(long long int nn) {
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      if ((i + j) % 2 == 0 && D[i][j] != nn) sum++;
      if ((i + j) % 2 != 0 && D[i][j] == nn) sum++;
    }
  }
  return sum;
}
struct st {
  long long int l;
  long long int r;
};
vector<st> V;
bool operator<(st a, st b) { return abs(a.l - a.r) > abs(b.l - b.r); }
int main() {
  scanf("%lld", &n);
  string str;
  for (long long int i = 1; i <= n; i++) {
    cin >> str;
    for (long long int j = 1; j <= n; j++) {
      A[i][j] = str[j - 1] - '0';
    }
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> str;
    for (long long int j = 1; j <= n; j++) {
      B[i][j] = str[j - 1] - '0';
    }
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> str;
    for (long long int j = 1; j <= n; j++) {
      C[i][j] = str[j - 1] - '0';
    }
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> str;
    for (long long int j = 1; j <= n; j++) {
      D[i][j] = str[j - 1] - '0';
    }
  }
  long long int A1 = Acost(1);
  long long int A0 = Acost(0);
  st ss;
  ss.l = A1;
  ss.r = A0;
  V.push_back(ss);
  long long int B1 = Bcost(1);
  long long int B0 = Bcost(0);
  ss.l = B1;
  ss.r = B0;
  V.push_back(ss);
  long long int C1 = Ccost(1);
  long long int C0 = Ccost(0);
  ss.l = C1;
  ss.r = C0;
  V.push_back(ss);
  long long int D1 = Dcost(1);
  long long int D0 = Dcost(0);
  ss.l = D1;
  ss.r = D0;
  V.push_back(ss);
  sort(V.begin(), V.end());
  long long int one = 0;
  long long int zero = 0;
  long long int ans = 0;
  long long int flex = 0;
  for (int i = 0; i < V.size(); i++) {
    st ss = V[i];
    long long int l = ss.l;
    long long int r = ss.r;
    if (l < r) {
      if (flex > 1) {
        one++;
        zero++;
        ans += l;
        flex--;
      } else if (one < 2) {
        ans += l;
        one++;
      } else {
        ans += r;
        zero++;
      }
    } else if (r < l) {
      if (flex > 1) {
        one++;
        zero++;
        ans += r;
        flex--;
      } else if (zero < 2) {
        ans += r;
        zero++;
      } else {
        ans += l;
        one++;
      }
    } else if (l == r) {
      flex++;
      ans += l;
    }
  }
  cout << ans << endl;
  return 0;
}
