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;
const long long INF = 1e18 + 1;
const int MAX = 200001;
const long long MOD = 1000000007;
struct trio {
  int first;
  int second;
  int third;
};
struct long_trio {
  long long first;
  long long second;
  long long third;
};
double dist_point_line(int x1, int y1, int x2, int y2, int x3, int y3) {
  double distance = abs((y3 - y1) * x2 - (x3 - x1) * y2 + x3 * y1 - x1 * y3) /
                    (2 * sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)));
  return distance;
}
double dist_point_point(int x1, int y1, int x2, int y2) {
  double distance = sqrt((x1 - y1) * (x1 - y1) + (x2 - y2) * (x2 - y2));
  return distance;
}
long long inq(long long k, long long q) {
  if (q == 0) return 1;
  long long l = inq(k, q / 2);
  if (q % 2 == 0)
    return l * l % MOD;
  else
    return l * l * k % MOD;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long cubr(long long a) {
  long long l = -1, r = 1e6 + 2;
  while (l < r - 1) {
    long long mid = (l + r) / 2;
    if (mid * mid * mid > a)
      r = mid;
    else
      l = mid;
  }
  return l;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long min(long long a, long long b) { return -1 * max(-a, -b); }
long long possible(long long q) {
  if (q == INF) return -1;
  return q;
}
bool correct(int x, int xx) {
  if (x < 0) return 0;
  if (x >= xx) return 0;
  return 1;
}
long long dsumm(long long x) {
  long long y = 1;
  long long z = 0;
  for (int i = 0; i < 18; i++) {
    z += x / y % 10;
    y *= 10;
  }
  return z;
}
string months[12] = {"January",   "February", "March",    "April",
                     "May",       "June",     "July",     "August",
                     "September", "October",  "November", "December"};
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long fact[13] = {1,    1,     2,      6,       24,       120,      720,
                      5040, 40320, 362280, 3622800, 39916800, 479001600};
int cx[6] = {1, -1, 0, 0, 0, 0};
int cy[6] = {0, 0, 1, -1, 0, 0};
int cz[6] = {0, 0, 0, 0, 1, -1};
long long n, m, k, ans = INF, l, r;
string s[5][300];
vector<int> perm;
int used[50];
void check() {
  string ss[300];
  for (int i = 0; i < n; i++) {
    ss[i] = s[perm[0]][i] + s[perm[1]][i];
  }
  for (int i = 0; i < n; i++) {
    ss[i + n] = s[perm[2]][i] + s[perm[3]][i];
  }
  int type1 = 0, type2 = 0;
  for (int i = 0; i < 2 * n; i++) {
    for (int j = 0; j < 2 * n; j++) {
      if ((i + j) % 2 == 0 && ss[i][j] == '1') {
        type1++;
      }
      if ((i + j) % 2 == 1 && ss[i][j] == '0') {
        type1++;
      }
      if ((i + j) % 2 == 1 && ss[i][j] == '1') {
        type2++;
      }
      if ((i + j) % 2 == 0 && ss[i][j] == '0') {
        type2++;
      }
    }
  }
  ans = min(ans, min(type1, type2));
  return;
}
void rec(int x) {
  if (x == 0) {
    check();
    return;
  }
  for (int i = 1; i <= 4; i++) {
    if (used[i] == 0) {
      used[i] = 1;
      perm.push_back(i);
      rec(x - 1);
      perm.pop_back();
      used[i] = 0;
    }
  }
  return;
}
int main() {
  cin >> n;
  for (int(i) = 0; (i) != (n); i++) cin >> s[1][i];
  for (int(i) = 0; (i) != (n); i++) cin >> s[2][i];
  for (int(i) = 0; (i) != (n); i++) cin >> s[3][i];
  for (int(i) = 0; (i) != (n); i++) cin >> s[4][i];
  rec(4);
  cout << ans;
}
