#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 4, inF = N * N * N;
int n, ans = inF;
string s[M][N];
vector<int> vec = {0, 1, 2, 3};
int check(int dex, int b) {
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      res += (s[dex][i][j] - '0' != ((i + j + b) & 1));
  return res;
}
int get(vector<int> vec) {
  int res = 0;
  for (int i = 0; i < M; i++) res += check(vec[i], i & 1);
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < n; j++) cin >> s[i][j];
  do {
    ans = min(ans, get(vec));
  } while (next_permutation(vec.begin(), vec.end()));
  cout << ans;
  return 0;
}
