#include <bits/stdc++.h>
using namespace std;
const int N = 102;
int n, a[N][N], ans[4][2];
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int k = 1; k <= 4; ++k) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) scanf("%1d", &a[i][j]);
    int start = 0;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) ans[k][0] += start ^ a[i][j], start ^= 1;
    sum += ans[k][0];
    start = 1;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) ans[k][1] += start ^ a[i][j], start ^= 1;
  }
  int res = 1000000000;
  for (int i = 1; i <= 4; ++i)
    for (int j = i + 1; j <= 4; ++j)
      res = min(res, sum + ans[i][1] - ans[i][0] + ans[j][1] - ans[j][0]);
  printf("%d\n", res);
  return 0;
}
