#include <bits/stdc++.h>
using namespace std;
int n, ans, chess[5][100][100], sumZero[5], sumOne[5];
vector<int> zero, one;
string s;
int main() {
  cin >> n;
  for (int k = 1; k < 5; k++) {
    for (int i = 1; i <= n; i++) {
      cin >> s;
      for (int j = 1; j <= n; j++) {
        chess[k][i][j] = (int)s[j - 1] - '0';
      }
    }
  }
  for (int k = 1; k < 5; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if ((i + j) & 1) {
          if (chess[k][i][j])
            sumOne[k]++;
          else
            sumZero[k]++;
        } else {
          if (chess[k][i][j] == 0)
            sumOne[k]++;
          else
            sumZero[k]++;
        }
      }
    }
    one.push_back(sumOne[k]);
    zero.push_back(sumZero[k]);
  }
  sort(one.begin(), one.end());
  sort(zero.begin(), zero.end());
  for (int i = 0; i < 2; i++) {
    ans += zero[i];
    ans += one[i];
  }
  cout << ans;
}
