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;
map<long long, map<long long, long long>> a;
map<long long, map<long long, long long>> b;
map<long long, map<long long, long long>> c;
map<long long, map<long long, long long>> d;
long long make(map<long long, map<long long, long long>> e, long long n) {
  long long cnt = 0;
  long long y = 1;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < n + 1; j++) {
      if (e[i][j] != y) {
        cnt++;
      }
      y ^= 1;
    }
  }
  return cnt;
}
long long mae(map<long long, map<long long, long long>> e, long long n) {
  long long cnt = 0;
  long long y = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < n + 1; j++) {
      if (e[i][j] != y) {
        cnt++;
      }
      y ^= 1;
    }
  }
  return cnt;
}
void inst(map<long long, map<long long, long long>> &g, long long n) {
  for (long long i = 1; i < n + 1; i++) {
    string h;
    cin >> h;
    for (long long j = 1; j < n + 1; j++) {
      g[i][j] = h[j - 1] - '0';
    }
  }
}
map<long long, map<long long, long long>> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  inst(a, n);
  inst(b, n);
  inst(c, n);
  inst(d, n);
  v[1][0] = mae(a, n);
  v[2][0] = mae(b, n);
  v[3][0] = mae(c, n);
  v[4][0] = mae(d, n);
  v[1][1] = make(a, n);
  v[2][1] = make(b, n);
  v[3][1] = make(c, n);
  v[4][1] = make(d, n);
  long long as = 0;
  long long ans = LLONG_MAX;
  for (long long i = 1; i < 5; i++) {
    long long x, y;
    for (long long j = i + 1; j < 5; j++) {
      set<long long> de;
      de.clear();
      for (long long hi = 1; hi < 5; hi++) {
        de.insert(hi);
      }
      de.erase(i);
      de.erase(j);
      x = *de.begin();
      de.erase(*de.begin());
      y = *de.begin();
      as = v[i][0] + v[j][0] + v[x][1] + v[y][1];
      ans = min(as, ans);
    }
  }
  cout << ans << "\n";
}
