#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1.5 * 1e7);
const int inf = ~0U >> 1;
const long long ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;
const int MOD = 1e9 + 7;
const long double pi = 3.14159265359;
int n, a[10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        char b;
        cin >> b;
        if (j % 2 == k % 2 && b == '0') a[i]++;
        if (j % 2 != k % 2 && b == '1') a[i]++;
      }
    }
  }
  sort(a, a + 4);
  cout << a[1] + a[0] + 2 * n * n - a[2] - a[3] << "\n";
}
