#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  bool b[4][n][n];
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      char c[n + 1];
      scanf("%s", &c);
      for (int k = 0; k < n; k++) b[i][j][k] = c[k] == '1' ? 1 : 0;
    }
  }
  int s[] = {0, 1, 2, 3}, mi = 1e9, co = 0;
  bool o = 0;
  do {
    for (int k = 0; k < 4; k += 2) {
      for (int j = 0; j < n; j++) {
        for (int i = 0; i < n; i++) {
          if (b[s[k]][j][i] != o) co++;
          o ^= 1;
        }
        for (int i = 0; i < n; i++) {
          if (b[s[k + 1]][j][i] != o) co++;
          o ^= 1;
        }
        o ^= 1;
      }
    }
    mi = min(mi, co);
    co = 0;
  } while (next_permutation(s, s + 4));
  cout << mi << "\n";
  return 0;
}
