#include <bits/stdc++.h>
const int mod = 1000000007;
using namespace std;
int main() {
  int n;
  cin >> n;
  char ch;
  int a[4], b[4];
  for (int i = 0; i < 4; i++) {
    a[i] = 0;
    b[i] = 0;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        cin >> ch;
        if ((k + j) % 2 == 0 && ch == '1') a[i]++;
        if ((k + j) % 2 == 1 && ch == '0') a[i]++;
        if ((k + j) % 2 == 0 && ch == '0') b[i]++;
        if ((k + j) % 2 == 1 && ch == '1') b[i]++;
      }
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (j == i) continue;
      int sum = a[i] + a[j];
      bool bb[4];
      for (int i = 0; i < 4; i++) bb[i] = 0;
      bb[i] = 1;
      bb[j] = 1;
      for (int m = 0; m < 4; m++)
        if (!bb[m]) sum += b[m];
      ans = min(ans, sum);
    }
  }
  cout << ans;
  return 0;
}
