#include <bits/stdc++.h>
using namespace std;
int a[5][107][107], b[5][107][107];
int p[10];
int ok[107][107];
int pok[107][107];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 4; ++i)
    for (int r = 1; r <= n; ++r)
      for (int c = 1; c <= n; ++c) {
        char ch;
        while (true) {
          cin >> ch;
          if (ch >= '0' && ch <= '1') {
            b[i][r][c] = ch - '0';
            break;
          }
        }
      }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if ((i + j) % 2 == 0)
        ok[i][j] = 1;
      else
        pok[i][j] = 1;
    }
  }
  int ans = 1e9;
  for (int i = 1; i <= 4; ++i) p[i] = i;
  int q = 0;
  do {
    q++;
    for (int i = 1; i <= 4; ++i) {
      for (int r = 1; r <= n; ++r)
        for (int c = 1; c <= n; ++c) a[i][r][c] = b[p[i]][r][c];
    }
    int cur = 0;
    for (int i = 1; i <= 4; ++i) {
      if (i % 2 == 1) {
        for (int r = 1; r <= n; ++r)
          for (int c = 1; c <= n; ++c) {
            cur += a[i][r][c] != ok[r][c];
          }
      } else {
        for (int r = 1; r <= n; ++r)
          for (int c = 1; c <= n; ++c) {
            cur += a[i][r][c] != pok[r][c];
          }
      }
    }
    ans = min(ans, cur);
  } while (next_permutation(p + 1, p + 5));
  cout << ans << endl;
  return 0;
}
