#include <bits/stdc++.h>
using namespace std;
int n, f[2][4], map[110][110], d[8];
char flag[110];
int main() {
  cin >> n;
  for (int i = 0; i < 4; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%s", flag);
      for (int k = 1; k <= n; ++k)
        f[0][i] += ((j & 1) ^ (k & 1)) ^ (flag[k - 1] == '0'),
            f[1][i] += ((j & 1) ^ (k & 1)) ^ (flag[k - 1] == '1');
    }
  }
  d[1] = f[0][0] + f[0][1] + f[1][2] + f[1][3];
  d[2] = f[0][0] + f[1][1] + f[0][2] + f[1][3];
  d[3] = f[1][0] + f[0][1] + f[0][2] + f[1][3];
  d[4] = f[0][0] + f[1][1] + f[1][2] + f[0][3];
  d[5] = f[1][0] + f[0][1] + f[1][2] + f[0][3];
  d[6] = f[1][0] + f[1][1] + f[0][2] + f[0][3];
  cout << min(min(d[5], min(min(min(d[1], d[2]), d[3]), d[4])), d[6]);
  return 0;
}
