#include <bits/stdc++.h>
using namespace std;
long long int n, ar[200][200], x1[200][200], x2[200][200];
string s[4][101];
inline long long int solve(long long int ord[]) {
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < n; j++) ar[i][j] = s[ord[0]][i][j] - '0';
  for (long long int i = 0; i < n; i++)
    for (long long int j = n; j < 2 * n; j++)
      ar[i][j] = s[ord[1]][i][j - n] - '0';
  for (long long int i = n; i < 2 * n; i++)
    for (long long int j = 0; j < n; j++) ar[i][j] = s[ord[2]][i - n][j] - '0';
  for (long long int i = n; i < 2 * n; i++)
    for (long long int j = n; j < 2 * n; j++)
      ar[i][j] = s[ord[3]][i - n][j - n] - '0';
  long long int ans1 = 0, ans2 = 0;
  for (long long int i = 0; i < 2 * n; i++)
    for (long long int j = 0; j < 2 * n; j++) ans1 += abs(x1[i][j] - ar[i][j]);
  for (long long int i = 0; i < 2 * n; i++)
    for (long long int j = 0; j < 2 * n; j++) ans2 += abs(x2[i][j] - ar[i][j]);
  return min(ans1, ans2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (long long int i = 0; i < 200; i++)
    for (long long int j = 0; j < 200; j++) x1[i][j] = (i + j) % 2;
  for (long long int i = 0; i < 200; i++)
    for (long long int j = 0; j < 200; j++) x2[i][j] = 1 - (i + j) % 2;
  cin >> n;
  for (long long int i = 0; i < 4; i++)
    for (long long int j = 0; j < n; j++) cin >> s[i][j];
  long long int ans = 1e18, ord[4] = {0, 1, 2, 3};
  do {
    ans = min(ans, solve(ord));
  } while (next_permutation(ord, ord + 4));
  cout << ans;
  return 0;
}
