#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e13;
const long long M = 1e9;
int n, a[15];
int main() {
  cin >> n;
  for (int k = 0; k < 4; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        char c;
        cin >> c;
        if (i % 2 == j % 2 && c == '0')
          a[k]++;
        else if (i % 2 != j % 2 && c == '1')
          a[k]++;
      }
    }
  }
  sort(a, a + 4);
  cout << a[0] + a[1] + 2 * n * n - a[2] - a[3] << endl;
}
