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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
namespace _c {
const double pi = acos(-1.0);
namespace min {
const int i8 = -128;
const int i16 = -32768;
const int i = -2147483647 - 1;
const long long l = -9223372036854775807LL - 1;
}  // namespace min
namespace max {
const int i8 = 127;
const int i16 = 32767;
const int i = 2147483647;
const long long l = 9223372036854775807LL;
}  // namespace max
}  // namespace _c
namespace _f {
template <typename T>
inline const T gcd(T m, T n) {
  while (n != 0) {
    T t = m % n;
    m = n;
    n = t;
  }
  return m;
}
template <typename T>
inline const T abs(const T &a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T pow(T a, T b) {
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
template <typename T>
inline T pow(T a, T b, const T &m) {
  a %= m;
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res % m;
}
}  // namespace _f
namespace io {
template <typename T>
inline T read() {
  register T res = 0, neg = 1;
  char g = getchar();
  for (; !isdigit(g); g = getchar()) {
    if (g == '-') {
      neg = -1;
    }
  }
  for (; isdigit(g); g = getchar()) {
    res = res * 10 + g - '0';
  }
  return res * neg;
}
template <typename T>
inline void read(T &t) {
  t = read<T>();
}
template <typename T>
inline void readln(const T first, const T last) {
  for (register T it = first; it != last; it++) {
    read(*it);
  }
}
template <typename T>
inline void _write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) {
    _write(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename T>
inline void write(const T &x, const char &sep = ' ') {
  _write(x);
  putchar(sep);
}
template <typename T>
inline void writeln(const T &x) {
  write(x, '\n');
}
template <typename T>
inline void writeln(const T first, const T last, const char &sep = ' ',
                    const char &ends = '\n') {
  for (register T it = first; it != last; it++) {
    write(*it, sep);
  }
  putchar(ends);
}
}  // namespace io
int n;
const int N = 100 + 5;
char mp[5][N][N];
char target[N][N];
int cnt[2][5];
int main() {
  io::read(n);
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%s", mp[i][j] + 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      target[i][j] = '0' + ((j & 1) == (i & 1));
    }
  }
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        cnt[(mp[i][j][k] == target[j][k])][i]++;
      }
    }
  }
  if (n & 1) {
    io::writeln(std::min({
        cnt[0][1] + cnt[0][2] + cnt[1][3] + cnt[1][4],
        cnt[0][1] + cnt[0][3] + cnt[1][2] + cnt[1][4],
        cnt[0][1] + cnt[0][4] + cnt[1][2] + cnt[1][3],
        cnt[0][2] + cnt[0][3] + cnt[1][1] + cnt[1][4],
        cnt[0][2] + cnt[0][4] + cnt[1][1] + cnt[1][3],
        cnt[0][3] + cnt[0][4] + cnt[1][1] + cnt[1][2],
    }));
  } else {
    int ans_1 = 0, ans_2 = 0;
    for (int i = 1; i <= 4; i++) {
      ans_1 += cnt[0][i];
      ans_2 += cnt[1][i];
    }
    io::writeln(std::min(ans_1, ans_2));
  }
}
