#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int, int>> need(4);
  for (int t = 0; t < 4; t++) {
    char board[110][110];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> board[i][j];
      }
    }
    int black = 0;
    int moves = 0;
    for (int i = 0; i < n; i++) {
      black = !black;
      for (int j = 0; j < n; j++) {
        if (j % 2 == 0) {
          if (board[i][j] - '0' != black) {
            moves++;
          }
        } else {
          if (board[i][j] - '0' == black) {
            moves++;
          }
        }
      }
    }
    need[t].first = moves;
    need[t].second = n * n - moves;
  }
  int ans = 0;
  sort(need.begin(), need.end());
  ans += need[0].first;
  ans += need[1].first;
  ans += need[2].second;
  ans += need[3].second;
  cout << ans << endl;
  return 0;
}
