#include <bits/stdc++.h>
using namespace std;
char arr[4][105][105];
int w[2][4];
int p[4];
int ans;
int n;
int calc(int id, int v) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (arr[id][i][j] != v + '0') {
        ++ret;
      }
      v ^= 1;
    }
  }
  return ret;
}
void solve() {
  scanf("%d", &n);
  for (int k = 0; k < 4; ++k) {
    for (int i = 0; i < n; ++i) {
      scanf("%s", arr[k][i]);
    }
  }
  for (int k = 0; k < 4; ++k) {
    for (int i = 0; i < 2; ++i) {
      w[i][k] = calc(k, i);
    }
  }
  for (int i = 0; i < 4; ++i) {
    p[i] = i;
  }
  ans = 1e9;
  do {
    for (int i = 0; i < 2; ++i) {
      int cur = 0;
      for (int j = 0; j < 4; ++j) {
        cur += w[(j == 0 || j == 3) ^ i][p[j]];
      }
      ans = min(ans, cur);
    }
  } while (next_permutation(p, p + 4));
  printf("%d\n", ans);
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
