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;
int main() {
  string str;
  long long int N, i, j, x, y;
  cin >> N;
  int a[N + 5][N + 5], b[N + 5][N + 5], c[N + 5][N + 5], d[N + 5][N + 5];
  for (i = 0; i < N; i++) {
    cin >> str;
    for (j = 0; j < N; j++) a[i][j] = str[j] - '0';
  }
  for (i = 0; i < N; i++) {
    cin >> str;
    for (j = 0; j < N; j++) b[i][j] = str[j] - '0';
  }
  for (i = 0; i < N; i++) {
    cin >> str;
    for (j = 0; j < N; j++) c[i][j] = str[j] - '0';
  }
  for (i = 0; i < N; i++) {
    cin >> str;
    for (j = 0; j < N; j++) d[i][j] = str[j] - '0';
  }
  vector<long long int> v1, v2, v3;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      v1.push_back(a[i][j]);
      v2.push_back(a[i][j]);
      v3.push_back(a[i][j]);
    }
    for (j = 0; j < N; j++) {
      v1.push_back(b[i][j]);
      v2.push_back(c[i][j]);
      v3.push_back(d[i][j]);
    }
  }
  vector<long long int> v6, v4, v5;
  for (i = 0; i < v1.size(); i++) {
    v4.push_back(v1[i]);
    v5.push_back(v2[i]);
    v6.push_back(v3[i]);
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      v1.push_back(c[i][j]);
      v4.push_back(d[i][j]);
      v2.push_back(b[i][j]);
      v5.push_back(d[i][j]);
      v3.push_back(b[i][j]);
      v6.push_back(c[i][j]);
    }
    for (j = 0; j < N; j++) {
      v1.push_back(d[i][j]);
      v4.push_back(c[i][j]);
      v2.push_back(d[i][j]);
      v5.push_back(b[i][j]);
      v3.push_back(c[i][j]);
      v6.push_back(b[i][j]);
    }
  }
  long long int c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12;
  c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = c9 = c10 = c11 = c12 = 0;
  x = 1;
  y = 0;
  long long int temp;
  for (i = 0; i < v1.size(); i++) {
    if (v1[i] != x) c1 += 1;
    if (v1[i] != y) c2 += 1;
    if (v2[i] != x) c3 += 1;
    if (v2[i] != y) c4 += 1;
    if (v3[i] != x) c5 += 1;
    if (v3[i] != y) c6 += 1;
    if (v4[i] != x) c7 += 1;
    if (v4[i] != y) c8 += 1;
    if (v5[i] != x) c9 += 1;
    if (v5[i] != y) c10 += 1;
    if (v6[i] != x) c11 += 1;
    if (v6[i] != y) c12 += 1;
    if ((i % (2 * N)) != (2 * N) - 1) {
      temp = x;
      x = y;
      y = temp;
    }
  }
  long long int min = 99999999999;
  min = min >= c1 ? c1 : min;
  min = min >= c2 ? c2 : min;
  min = min >= c3 ? c3 : min;
  min = min >= c4 ? c4 : min;
  min = min >= c5 ? c5 : min;
  min = min >= c6 ? c6 : min;
  min = min >= c7 ? c7 : min;
  min = min >= c8 ? c8 : min;
  min = min >= c9 ? c9 : min;
  min = min >= c10 ? c10 : min;
  min = min >= c11 ? c11 : min;
  min = min >= c12 ? c12 : min;
  cout << min << endl;
  return 0;
}
