#include <bits/stdc++.h>
using namespace std;
const int PI = 3.141592653589793;
const int inf = 1000111222;
const int N = 100007;
string chess[500];
int first[100], change[100], ans, bit[200];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int j = 0; j < 4; j++) {
    for (int i = 0; i < n; i++) cin >> chess[i];
    first[j] += (chess[0][0] == '1');
    int flag = first[j];
    for (int a = 0; a < n; a++) {
      for (int b = 0; b < n; b++) {
        int just = chess[a][b] - '0';
        if (just != flag) {
          change[j]++;
        }
        flag ^= 1;
      }
    }
  }
  ans = inf;
  for (int i = 0; i < 15; i++) {
    int cnt = 0;
    for (int i = 0; i < 20; i++) {
      bit[i] = 0;
    }
    for (int t = 0; t < 5; t++) {
      if ((1 << t) & i) {
        cnt++;
        bit[t] = 1;
      }
    }
    if (cnt != 2) continue;
    int curr = 0;
    for (int t = 0; t < 4; t++) {
      if (bit[t] == first[t]) {
        curr += change[t];
      } else {
        int x = n * n - change[t];
        curr += x;
      }
    }
    ans = min(ans, curr);
  }
  cout << ans << "\n";
  return 0;
}
