#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 60) - 1;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
int main() {
  int n;
  cin >> n;
  vector<vector<string> > a(4, vector<string>(n));
  for (int k = 0; k < 4; k++)
    for (int i = 0; i < n; i++) cin >> a[k][i];
  vector<int> p(4);
  vector<vector<int> > cnt(4, vector<int>(2, 0));
  for (int k = 0; k < 4; k++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if ((i + j) % 2 != a[k][i][j] - '0') cnt[k][0]++;
      }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if ((i + j + 1) % 2 != a[k][i][j] - '0') cnt[k][1]++;
      }
  }
  for (int i = 0; i < 4; i++) p[i] = i;
  int ans = INF;
  do {
    for (int c = 0; c < 2; c++)
      chmin(ans,
            cnt[p[0]][c] + cnt[p[3]][c] + cnt[p[1]][1 - c] + cnt[p[2]][1 - c]);
  } while (next_permutation(p.begin(), p.end()));
  cout << ans << endl;
  return 0;
}
