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 double pi = acos(-1.0);
long long findsum(long long color, string s[], long long n) {
  long long i, j;
  long long count = 0;
  char col = color + '0';
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if ((i + j) % 2 == 0) {
        if (s[i][j] != col) count++;
      } else {
        if (s[i][j] == col) count++;
      }
    }
  }
  return count;
}
long long findans(long long n1, long long n2, long long n3, long long n4,
                  string s1[], string s2[], string s3[], string s4[],
                  long long n) {
  long long sum = n1 + n2 + n3 + n4;
  if (sum != 2) return 10000000000000;
  long long sum1, sum2, sum3, sum4;
  sum1 = findsum(n1, s1, n);
  sum2 = findsum(n2, s2, n);
  sum3 = findsum(n3, s3, n);
  sum4 = findsum(n4, s4, n);
  return sum1 + sum2 + sum3 + sum4;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  long long i, j, n, m, k;
  cin >> n;
  string s1[n], s2[n], s3[n], s4[n];
  for (i = 0; i < n; i++) cin >> s1[i];
  for (i = 0; i < n; i++) cin >> s2[i];
  for (i = 0; i < n; i++) cin >> s3[i];
  for (i = 0; i < n; i++) cin >> s4[i];
  long long l;
  long long ans = 10000000000000;
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 2; k++) {
        for (l = 0; l < 2; l++) {
          ans = min(ans, findans(i, j, k, l, s1, s2, s3, s4, n));
        }
      }
    }
  }
  cout << ans;
  return 0;
}
