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;
clock_t __start;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long double eps = 1e-8l;
const long long INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
const long double Pi = acosl(-1.0l);
int __loc = 1;
int __io_opt = 1;
int __fileIO = 0;
int __MulTest = 0;
const char* __fin = "in";
const char* __fout = "out";
const char* __err = "err";
void prec();
void load();
void solve();
void __time(string s) {
  if (!__loc) return;
  cerr << s + ". Time: " << ((long double)clock() - __start) / CLOCKS_PER_SEC
       << '\n';
}
struct app {
  void __io_set() {
    __loc = 0;
    if (__io_opt) {
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
    }
    cout.precision(9);
    cout.setf(ios::fixed | ios::showpoint);
    if (__loc || __fileIO) {
      freopen(__fin, "r", stdin);
      freopen(__fout, "w", stdout);
    }
    if (__loc) freopen(__err, "w", stderr);
  }
  app() {
    __io_set();
    __start = clock();
    prec();
    __time("Precalc finised");
    int ts = 1;
    if (__MulTest) cin >> ts;
    while (ts--) {
      load();
      solve();
    }
    __time("Program finished");
  }
};
int main() { app x; }
void prec() {}
int n;
pair<int, int> block() {
  int t = 0, t2 = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (0) log(i);
    for (int j = 0; j < n; j++) {
      int c1 = (i + j) % 2;
      if (0) log(c1);
      if (0) log(s[j] - '0');
      if (s[j] - '0' != c1) t++;
      if (s[j] - '0' != !c1) t2++;
    }
  }
  return make_pair(t, t2);
}
void load() {
  vector<int> a, b;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    auto x = block();
    if (0) log(i);
    if (0) log(x.first);
    if (0) log(x.second);
    a.push_back(x.first);
    b.push_back(x.second);
  }
  sort((a).begin(), (a).end());
  sort((b).begin(), (b).end());
  cout << a[0] + a[1] + b[0] + b[1];
}
void solve() {}
