#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
char in[4][105][105];
char cur[205][205];
int u[4];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) scanf("%s", in[i][j]);
  for (int i = 0; i < 4; i++) u[i] = i;
  int ans = INF;
  do {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          cur[(i / 2) * n + j][(i % 2) * n + k] = in[u[i]][j][k];
    }
    int cnt = 0;
    for (int i = 0; i < 2 * n; i++) {
      for (int j = 0; j < 2 * n; j++) {
        char c = '0' + (i + j) % 2;
        if (c != cur[i][j]) cnt++;
      }
    }
    ans = min(ans, cnt);
  } while (next_permutation(u, u + 4));
  return printf("%d\n", ans), 0;
}
