#include <bits/stdc++.h>
using namespace std;
int n;
int a[5][101][101];
int sd[5][3];
int main() {
  scanf("%d", &n);
  for (int t = 1; t <= 4; t++) {
    char ss[101];
    for (int i = 1; i <= n; i++) {
      scanf("%s", ss + 1);
      for (int j = 1; j <= n; j++) {
        int f = ss[j] - '0';
        a[t][i][j] = f;
      }
    }
  }
  for (int t = 1; t <= 4; t++) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (((i - 1) * n + j) % 2 == 1 && a[t][i][j] == 0) sd[t][1]++;
        if (((i - 1) * n + j) % 2 == 0 && a[t][i][j] == 1) sd[t][1]++;
        if (((i - 1) * n + j) % 2 == 1 && a[t][i][j] == 1) sd[t][2]++;
        if (((i - 1) * n + j) % 2 == 0 && a[t][i][j] == 0) sd[t][2]++;
      }
  }
  int ans = 1e9;
  if (sd[1][1] + sd[2][1] + sd[3][2] + sd[4][2] < ans)
    ans = sd[1][1] + sd[2][1] + sd[3][2] + sd[4][2];
  if (sd[1][1] + sd[3][1] + sd[2][2] + sd[4][2] < ans)
    ans = sd[1][1] + sd[3][1] + sd[2][2] + sd[4][2];
  if (sd[1][1] + sd[4][1] + sd[3][2] + sd[2][2] < ans)
    ans = sd[1][1] + sd[4][1] + sd[3][2] + sd[2][2];
  if (sd[1][2] + sd[2][2] + sd[3][1] + sd[4][1] < ans)
    ans = sd[1][2] + sd[2][2] + sd[3][1] + sd[4][1];
  if (sd[1][2] + sd[3][2] + sd[2][1] + sd[4][1] < ans)
    ans = sd[1][2] + sd[3][2] + sd[2][1] + sd[4][1];
  if (sd[1][2] + sd[4][2] + sd[3][1] + sd[2][1] < ans)
    ans = sd[1][2] + sd[4][2] + sd[3][1] + sd[2][1];
  printf("%d", ans);
  return 0;
}
