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 k;
char a[51][51];
int spf[1000000];
int vs[51][51];
set<int> s;
long long maxPrimeFactors(long long n) {
  long long maxPrime = -1;
  while (n % 2 == 0) {
    maxPrime = 2;
    n >>= 1;
  }
  for (int i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      maxPrime = i;
      n = n / i;
    }
  }
  if (n > 2) maxPrime = n;
  return maxPrime;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long LCM, f = 0;
  if (max(a, b) % min(a, b) == 0)
    LCM = max(a, b);
  else {
    LCM = (a * b * 1LL) / gcd(a, b);
    if (LCM % a == 0 && LCM % b == 0) f = 1;
    if (!f || LCM < 0) return 0;
  }
  return LCM;
}
long long binarysearch(long long a[], long long t, long long low,
                       long long high) {
  long long mid = (low + high) / 2;
  if (t <= a[mid] && t > a[mid - 1]) {
    if (a[mid] == t)
      return mid;
    else
      return mid - 1;
  } else if (t <= a[mid - 1])
    binarysearch(a, t, low, mid - 1);
  else
    binarysearch(a, t, mid + 1, high);
}
void sieve(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * 2; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) s.insert(p);
}
void sieve2() {
  spf[1] = 1;
  for (int i = 2; i < 1000000; i++) spf[i] = i;
  for (int i = 4; i < 1000000; i += 2) spf[i] = 2;
  for (int i = 3; i * i < 1000000; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < 1000000; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  pair<int, int> as[5];
  int sum = 0;
  for (int p = 1; p <= 4; p++) {
    char a[n + 1][n + 1];
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) cin >> a[i][j];
    int count = 0;
    char prev = '1';
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == prev) count++;
        if (prev == '0')
          prev = '1';
        else
          prev = '0';
      }
    sum += count;
    as[p].first = count;
    count = 0;
    prev = '0';
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == prev) count++;
        if (prev == '0')
          prev = '1';
        else
          prev = '0';
      }
    as[p].second = count;
  }
  int ans = 1000000;
  for (int i = 1; i < 4; i++)
    for (int j = i + 1; j <= 4; j++)
      ans = min(ans,
                as[i].second + as[j].second + sum - as[i].first - as[j].first);
  cout << ans;
  return 0;
}
