#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, neg = 1;
  char c = getchar();
  while (c < 48 || c > 57) {
    if (c == 45) neg = -neg;
    c = getchar();
  }
  while (c >= 48 && c <= 57) {
    x = (x << 1) + (x << 3) + c - 48;
    c = getchar();
  }
  return x * neg;
}
inline void no() { cout << "NO\n"; }
inline void yes() { cout << "YES\n"; }
const int omg = 1e9, mod = 1e9 + 7;
void solve() {
  int N;
  cin >> N;
  int arr[4] = {0};
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        char c;
        cin >> c;
        if ((c == '0' && k % 2 == j % 2) || c == '1' && k % 2 != j % 2)
          arr[i]++;
      }
    }
  }
  sort(arr, arr + 4);
  cout << arr[0] + arr[1] - arr[2] - arr[3] + 2 * pow(N, 2);
}
signed main() {
  solve();
  return 0;
}
