#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n;
int arr[5][110][110];
int cost[5][5];
int calc(int idx, int color) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[idx][i][j] != color) res++;
      color = 1 - color;
    }
  }
  return res;
}
int main() {
  memset(cost, 0, sizeof(cost));
  cin >> n;
  string s;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> s;
      for (int k = 0; k < n; k++) {
        arr[i][j][k] = s[k] - '0';
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 2; j++) {
      cost[i][j] = calc(i, j);
    }
  }
  int mini = INF;
  mini = min(mini, cost[0][0] + cost[1][0] + cost[2][1] + cost[3][1]);
  mini = min(mini, cost[0][0] + cost[1][1] + cost[2][0] + cost[3][1]);
  mini = min(mini, cost[0][0] + cost[1][1] + cost[2][1] + cost[3][0]);
  mini = min(mini, cost[0][1] + cost[1][0] + cost[2][0] + cost[3][1]);
  mini = min(mini, cost[0][1] + cost[1][0] + cost[2][1] + cost[3][0]);
  mini = min(mini, cost[0][1] + cost[1][1] + cost[2][0] + cost[3][0]);
  cout << mini << endl;
  return 0;
}
