#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
char s[5][109][109];
char str[209][209];
int a[5];
int main() {
  char x;
  int cnt, ans, n, m;
  while (cin >> n) {
    ans = inf;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < n; j++) scanf("%s", s[i][j]);
    m = (n << 1);
    for (int i = 0; i < 4; i++) a[i] = i;
    do {
      cnt = 0;
      for (int i = 0; i < 4; i++)
        for (int j = 0; j < n; j++)
          for (int k = 0; k < n; k++)
            str[(i / 2) * n + j][(i % 2) * n + k] = s[a[i]][j][k];
      for (int i = 0; i < m; i++)
        for (int j = 0; j < m; j++) {
          x = ((i + j) % 2) + '0';
          if (x != str[i][j]) cnt++;
        }
      ans = min(ans, cnt);
    } while (next_permutation(a, a + 4));
    cout << ans << endl;
  }
  return 0;
}
