#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 47;
const long long LINF = (long long)INF * INF;
const int MAX = 2e5;
const double EPS = 1e-9;
const double PI = acos(-1.);
int n;
int a[4][101][101];
int paint(int x, int col) {
  int cnt = 0;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      if (a[x][i][j] % 2 != (i + j + col) % 2) {
        cnt++;
      }
    }
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  int best = INF;
  cin >> n;
  for (int i = (0); i < (4); ++i) {
    for (int j = (0); j < (n); ++j) {
      string second;
      cin >> second;
      for (int k = (0); k < (n); ++k) {
        a[i][j][k] = second[k] - '0';
      }
    }
  }
  int p[4];
  for (int c = (0); c < (2); ++c) {
    for (int i = (0); i < (4); ++i) p[i] = i;
    do {
      int cur = 0;
      for (int i = (0); i < (4); ++i) {
        cur += paint(p[i], (i + c) % 2);
      }
      best = min(best, cur);
    } while (next_permutation(p, p + 4));
  }
  cout << best << endl;
}
