#include <bits/stdc++.h>
using namespace std;
map<long long, map<long long, long long>> a;
map<long long, map<long long, long long>> b;
map<long long, map<long long, long long>> c;
map<long long, map<long long, long long>> d;
long long make(map<long long, map<long long, long long>> e, long long n) {
  long long cnt = 0;
  long long y = 1;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < n + 1; j++) {
      if (e[i][j] != y) {
        cnt++;
      }
      y ^= 1;
    }
  }
  return cnt;
}
long long mae(map<long long, map<long long, long long>> e, long long n) {
  long long cnt = 0;
  long long y = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < n + 1; j++) {
      if (e[i][j] != y) {
        cnt++;
      }
      y ^= 1;
    }
  }
  return cnt;
}
void inst(map<long long, map<long long, long long>> &g, long long n) {
  for (long long i = 1; i < n + 1; i++) {
    string h;
    cin >> h;
    for (long long j = 1; j < n + 1; j++) {
      g[i][j] = h[j - 1] - '0';
    }
  }
}
map<long long, map<long long, long long>> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  inst(a, n);
  inst(b, n);
  inst(c, n);
  inst(d, n);
  v[1][0] = mae(a, n);
  v[2][0] = mae(b, n);
  v[3][0] = mae(c, n);
  v[4][0] = mae(d, n);
  v[1][1] = make(a, n);
  v[2][1] = make(b, n);
  v[3][1] = make(c, n);
  v[4][1] = make(d, n);
  long long as = 0;
  long long ans = LLONG_MAX;
  for (long long i = 1; i < 5; i++) {
    long long x, y;
    for (long long j = i + 1; j < 5; j++) {
      set<long long> de;
      de.clear();
      for (long long hi = 1; hi < 5; hi++) {
        de.insert(hi);
      }
      de.erase(i);
      de.erase(j);
      x = *de.begin();
      de.erase(*de.begin());
      y = *de.begin();
      as = v[i][0] + v[j][0] + v[x][1] + v[y][1];
      ans = min(as, ans);
    }
  }
  cout << ans << "\n";
}
