#include <bits/stdc++.h>
using namespace std;
char a[105][105];
int m1[4], m2[4];
int n, ans;
int main() {
  ans = 99999;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[j];
      for (int k = 0; k < n; k++) {
        if ((j + k) % 2 == 0) {
          if (a[j][k] - '0' == 1)
            m2[i]++;
          else
            m1[i]++;
        } else {
          if (a[j][k] - '0' == 1)
            m1[i]++;
          else
            m2[i]++;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 4; j++) {
      int sum = 0;
      for (int k = 0; k < 4; k++)
        if (k != i && k != j) sum += m2[k];
      sum += (m1[i] + m1[j]);
      ans = min(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}
