#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z;
string str[5][200];
int blcks[5], whites[5];
int ara[] = {0, 1, 2, 3};
int main() {
  cin >> n;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) cin >> str[i][j];
    int tmp = 0;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if ((j + k) % 2 == 0) {
          if (str[i][j][k] == '0')
            blcks[i]++;
          else
            whites[i]++;
        } else {
          if (str[i][j][k] == '1')
            blcks[i]++;
          else
            whites[i]++;
        }
      }
    }
  }
  int ans = 100000000;
  do {
    int tmp1 = whites[ara[0]] + blcks[ara[1]] + whites[ara[2]] + blcks[ara[3]];
    int tmp2 = whites[ara[1]] + blcks[ara[0]] + whites[ara[3]] + blcks[ara[2]];
    ans = min(ans, tmp1);
    ans = min(ans, tmp2);
  } while (next_permutation(ara, ara + 4));
  cout << ans << endl;
  return 0;
}
