#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, m, n, i, j, k = 0, l = 0, p = 0, q, ct;
  cin >> n;
  char a[n][n];
  long long b[5], c[5];
  j = 4;
  for (k = 0; k < 4; k++) {
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) cin >> a[i][j];
    }
    l = 1;
    ct = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if ((a[i][j] - '0') != l) ct++;
        l = abs(l - 1);
      }
    }
    b[k] = ct;
    l = 0;
    ct = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if ((a[i][j] - '0') != l) ct++;
        l = abs(l - 1);
      }
    }
    c[k] = ct;
  }
  ct = 0;
  sort(b, b + 4);
  sort(c, c + 4);
  ct += b[0] + b[1] + c[0] + c[1];
  cout << ct << endl;
  return 0;
}
