#include <bits/stdc++.h>
using namespace std;
vector<vector<string>> a(4);
char b[110][110], c[110][110];
int cnt1[4], cnt2[4];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    a[i].resize(n);
    for (int j = 0; j < n; j++) cin >> a[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      b[i][j] = (i + j) % 2 + '0';
    }
  }
  for (int i = 0; i < 4; i++) {
    int cn1 = 0, cn2 = 0;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (b[j][k] == a[i][j][k])
          cn1++;
        else
          cn2++;
      }
    }
    cnt1[i] = cn1;
    cnt2[i] = cn2;
  }
  int ans = INT_MAX;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      int cur = cnt1[i] + cnt1[j];
      for (int k = 0; k < 4; k++) {
        if (k != i && k != j) cur += cnt2[k];
      }
      ans = min(ans, cur);
    }
  }
  cout << ans << "\n";
  return 0;
}
