#include <bits/stdc++.h>
using namespace std;
pair<int, int> oddeven(string arr[], int n) {
  int odd = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int number = n * i + j;
      if ((number & 1) && (arr[i][j] == '1'))
        ++odd;
      else if ((number % 2 == 0) && (arr[i][j] == '0'))
        ++odd;
    }
  }
  int even = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int number = n * i + j;
      if ((number & 1) && (arr[i][j] == '0'))
        ++even;
      else if ((number % 2 == 0) && (arr[i][j] == '1'))
        ++even;
    }
  }
  return {odd, even};
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > ans;
  for (int i = 0; i < 4; ++i) {
    string arr[n];
    for (int i = 0; i < n; ++i) cin >> arr[i];
    ans.push_back(oddeven(arr, n));
    string s;
    getline(cin, s);
    cin.clear();
  }
  long long anss = 2147483647;
  anss = min(anss,
             0ll + ans[0].first + ans[1].first + ans[2].second + ans[3].second);
  anss = min(anss,
             0ll + ans[0].first + ans[1].second + ans[2].first + ans[3].second);
  anss = min(anss,
             0ll + ans[0].first + ans[1].second + ans[2].second + ans[3].first);
  anss = min(anss,
             0ll + ans[0].second + ans[1].first + ans[2].first + ans[3].second);
  anss = min(anss,
             0ll + ans[0].second + ans[1].first + ans[2].second + ans[3].first);
  anss = min(anss,
             0ll + ans[0].second + ans[1].second + ans[2].first + ans[3].first);
  cout << anss;
}
