#include <bits/stdc++.h>
using namespace std;
string A[4][102];
string M[202];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int p = 0; p < 4; p++) {
    for (int i = 0; i < n; i++) {
      cin >> A[p][i];
    }
  }
  vector<int> T;
  for (int i = 0; i < 4; i++) T.push_back(i);
  int ans = int(1e9);
  do {
    for (int i = 0; i < n; i++) M[i] = A[T[0]][i] + A[T[1]][i];
    for (int i = n; i < 2 * n; i++) M[i] = A[T[2]][i - n] + A[T[3]][i - n];
    int op1 = 0, op2 = 0;
    for (int i = 0; i < 2 * n; i++) {
      int sq = (i % 2) ? 1 : 0;
      for (int j = 0; j < 2 * n; j++) {
        if (M[i][j] - '0' != sq) op1++;
        sq ^= 1;
      }
    }
    for (int i = 0; i < 2 * n; i++) {
      int sq = (i % 2) ? 0 : 1;
      for (int j = 0; j < 2 * n; j++) {
        if (M[i][j] - '0' != sq) op2++;
        sq ^= 1;
      }
    }
    ans = min(ans, min(op1, op2));
  } while (next_permutation(T.begin(), T.end()));
  cout << ans << endl;
}
