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;
vector<string> a;
vector<string> b;
vector<string> c;
vector<string> d;
long long int B[100], W[100];
long long int ignorar;
long long int n;
bool ok;
long long int to_black(vector<string> x) {
  long long int number = 0;
  bool black = true;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      ignorar = x[i][j] - '0';
      if ((ignorar & 1) && black) {
        ok = true;
      } else {
        if ((ignorar ^ 1) && black == false) {
          ok = true;
        } else {
          number++;
        }
      }
      if (black == true) {
        black = false;
      } else {
        black = true;
      }
    }
  }
  return number;
}
long long int to_white(vector<string> x) {
  long long int number = 0;
  bool white = true;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (x[i][j] == '0' && white) {
        ok = true;
      } else {
        if (x[i][j] == '1' && white == false) {
          ok = true;
        } else {
          number++;
        }
      }
      if (white == true) {
        white = false;
      } else {
        white = true;
      }
    }
  }
  return number;
}
int main() {
  string s;
  long long int aux, ans = 1e10;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    a.push_back(s);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    b.push_back(s);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    c.push_back(s);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    d.push_back(s);
  }
  B[1] = to_black(a);
  B[2] = to_black(b);
  B[3] = to_black(c);
  B[4] = to_black(d);
  W[1] = to_white(a);
  W[2] = to_white(b);
  W[3] = to_white(c);
  W[4] = to_white(d);
  aux = (B[1] + B[2]) + (W[3] + W[4]);
  ans = min(ans, aux);
  aux = (W[1] + W[2]) + (B[3] + B[4]);
  ans = min(ans, aux);
  aux = (B[1] + B[3]) + (W[2] + W[4]);
  ans = min(ans, aux);
  aux = (W[1] + W[3]) + (B[2] + B[4]);
  ans = min(ans, aux);
  aux = (B[1] + B[4]) + (W[2] + W[3]);
  ans = min(ans, aux);
  aux = (W[1] + W[4]) + (B[2] + B[3]);
  ans = min(ans, aux);
  cout << ans;
}
