#include <bits/stdc++.h>
char a[101][101];
int diff(int n) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i + j) & 1 && a[i][j] == '1') {
        ans++;
      }
      if (!((i + j) & 1) && a[i][j] == '0') {
        ans++;
      }
    }
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  int d[4];
  for (int k = 0; k < 4; k++) {
    for (int i = 0; i < n; i++) {
      scanf("%s", a[i]);
    }
    d[k] = diff(n);
  }
  std::sort(d, d + 4);
  printf("%d\n", d[0] + d[1] + n * n - d[2] + n * n - d[3]);
  return 0;
}
