#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
int n;
char a[4][105][105], pattern[2][500][500];
int check(int id, int x, int y, char p[500][500]) {
  int ans = 0;
  for (int i = 0, _n = (int)(n); i < _n; ++i)
    for (int j = 0, _n = (int)(n); j < _n; ++j) {
      if (a[id][i][j] != p[x + i][y + j]) ans++;
    }
  return ans;
}
int solve_h(int i, int j, int k, int l, char p[500][500]) {
  return check(i, 0, 0, p) + check(j, 0, n, p) + check(k, n, 0, p) +
         check(l, n, n, p);
}
int solve(int i, int j, int k, int l) {
  return min(solve_h(i, j, k, l, pattern[0]), solve_h(i, j, k, l, pattern[1]));
}
int main() {
  while (cin >> n) {
    memset(a, (0), sizeof(a));
    memset(pattern, ('3'), sizeof(pattern));
    for (int i = 0; i < 4; i++) {
      for (int j = 0, _n = (int)(n); j < _n; ++j)
        for (int k = 0, _n = (int)(n); k < _n; ++k) cin >> a[i][j][k];
    }
    pattern[0][0][0] = '0';
    for (int i = 0, _n = (int)(2 * n); i < _n; ++i)
      for (int j = 0, _n = (int)(2 * n); j < _n; ++j) {
        if (pattern[0][i][j] == '3') {
          if (j > 0)
            pattern[0][i][j] = '0' + '1' - pattern[0][i][j - 1];
          else if (i > 0)
            pattern[0][i][j] = '0' + '1' - pattern[0][i - 1][j];
        }
      }
    pattern[1][0][0] = '1';
    for (int i = 0, _n = (int)(2 * n); i < _n; ++i)
      for (int j = 0, _n = (int)(2 * n); j < _n; ++j) {
        if (pattern[1][i][j] == '3') {
          if (j > 0)
            pattern[1][i][j] = '0' + '1' - pattern[1][i][j - 1];
          else if (i > 0)
            pattern[1][i][j] = '0' + '1' - pattern[1][i - 1][j];
        }
      }
    int ans = 100000000;
    for (int i = 0, _n = (int)(4); i < _n; ++i)
      for (int j = 0, _n = (int)(4); j < _n; ++j)
        for (int k = 0, _n = (int)(4); k < _n; ++k)
          for (int l = 0, _n = (int)(4); l < _n; ++l) {
            if (i != j && i != k && i != l && j != k && j != l && k != l)
              ans = min(ans, solve(i, j, k, l));
          }
    cout << ans << endl;
  }
  return 0;
}
