#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 7;
long long int n, jad[4][MAXN][MAXN];
long long int check(long long int ul[MAXN][MAXN], long long int ur[MAXN][MAXN],
                    long long int dl[MAXN][MAXN], long long int dr[MAXN][MAXN],
                    long long int st) {
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (st != ul[i][j]) ans++;
      st = 1 - st;
    }
    for (long long int j = 0; j < n; j++) {
      if (st != ur[i][j]) ans++;
      st = 1 - st;
    }
    st = 1 - st;
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (st != dl[i][j]) ans++;
      st = 1 - st;
    }
    for (long long int j = 0; j < n; j++) {
      if (st != dr[i][j]) ans++;
      st = 1 - st;
    }
    st = 1 - st;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long int per[] = {0, 1, 2, 3};
  long long int ans = 1e9;
  for (long long int ii = 0; ii < 4; ii++) {
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < n; j++) {
        char c;
        cin >> c;
        jad[ii][i][j] = c - '0';
      }
    }
  }
  do {
    ans =
        min(ans, check(jad[per[0]], jad[per[1]], jad[per[2]], jad[per[3]], 0));
    ans =
        min(ans, check(jad[per[0]], jad[per[1]], jad[per[2]], jad[per[3]], 1));
  } while (next_permutation(per, per + 4));
  cout << ans;
}
