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;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
int n;
char a[4][105][105], pattern[2][500][500];
int check(int id, int x, int y, char p[500][500]) {
  int ans = 0;
  for (int i = 0, _n = (int)(n); i < _n; ++i)
    for (int j = 0, _n = (int)(n); j < _n; ++j) {
      if (a[id][i][j] != p[x + i][y + j]) ans++;
    }
  return ans;
}
int solve_h(int i, int j, int k, int l, char p[500][500]) {
  return check(i, 0, 0, p) + check(j, 0, n, p) + check(k, n, 0, p) +
         check(l, n, n, p);
}
int solve(int i, int j, int k, int l) {
  return min(solve_h(i, j, k, l, pattern[0]), solve_h(i, j, k, l, pattern[1]));
}
int main() {
  while (cin >> n) {
    memset(a, (0), sizeof(a));
    memset(pattern, ('3'), sizeof(pattern));
    for (int i = 0; i < 4; i++) {
      for (int j = 0, _n = (int)(n); j < _n; ++j)
        for (int k = 0, _n = (int)(n); k < _n; ++k) cin >> a[i][j][k];
    }
    pattern[0][0][0] = '0';
    for (int i = 0, _n = (int)(2 * n); i < _n; ++i)
      for (int j = 0, _n = (int)(2 * n); j < _n; ++j) {
        if (pattern[0][i][j] == '3') {
          if (j > 0)
            pattern[0][i][j] = '0' + '1' - pattern[0][i][j - 1];
          else if (i > 0)
            pattern[0][i][j] = '0' + '1' - pattern[0][i - 1][j];
        }
      }
    pattern[1][0][0] = '1';
    for (int i = 0, _n = (int)(2 * n); i < _n; ++i)
      for (int j = 0, _n = (int)(2 * n); j < _n; ++j) {
        if (pattern[1][i][j] == '3') {
          if (j > 0)
            pattern[1][i][j] = '0' + '1' - pattern[1][i][j - 1];
          else if (i > 0)
            pattern[1][i][j] = '0' + '1' - pattern[1][i - 1][j];
        }
      }
    int ans = 100000000;
    for (int i = 0, _n = (int)(4); i < _n; ++i)
      for (int j = 0, _n = (int)(4); j < _n; ++j)
        for (int k = 0, _n = (int)(4); k < _n; ++k)
          for (int l = 0, _n = (int)(4); l < _n; ++l) {
            if (i != j && i != k && i != l && j != k && j != l && k != l)
              ans = min(ans, solve(i, j, k, l));
          }
    cout << ans << endl;
  }
  return 0;
}
