#include <bits/stdc++.h>
using namespace std;
vector<string> a;
vector<string> b;
vector<string> c;
vector<string> d;
long long int B[100], W[100];
long long int ignorar;
long long int n;
bool ok;
long long int to_black(vector<string> x) {
  long long int number = 0;
  bool black = true;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      ignorar = x[i][j] - '0';
      if ((ignorar & 1) && black) {
        ok = true;
      } else {
        if ((ignorar ^ 1) && black == false) {
          ok = true;
        } else {
          number++;
        }
      }
      if (black == true) {
        black = false;
      } else {
        black = true;
      }
    }
  }
  return number;
}
long long int to_white(vector<string> x) {
  long long int number = 0;
  bool white = true;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (x[i][j] == '0' && white) {
        ok = true;
      } else {
        if (x[i][j] == '1' && white == false) {
          ok = true;
        } else {
          number++;
        }
      }
      if (white == true) {
        white = false;
      } else {
        white = true;
      }
    }
  }
  return number;
}
int main() {
  string s;
  long long int aux, ans = 1e10;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    a.push_back(s);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    b.push_back(s);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    c.push_back(s);
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    d.push_back(s);
  }
  B[1] = to_black(a);
  B[2] = to_black(b);
  B[3] = to_black(c);
  B[4] = to_black(d);
  W[1] = to_white(a);
  W[2] = to_white(b);
  W[3] = to_white(c);
  W[4] = to_white(d);
  aux = (B[1] + B[2]) + (W[3] + W[4]);
  ans = min(ans, aux);
  aux = (W[1] + W[2]) + (B[3] + B[4]);
  ans = min(ans, aux);
  aux = (B[1] + B[3]) + (W[2] + W[4]);
  ans = min(ans, aux);
  aux = (W[1] + W[3]) + (B[2] + B[4]);
  ans = min(ans, aux);
  aux = (B[1] + B[4]) + (W[2] + W[3]);
  ans = min(ans, aux);
  aux = (W[1] + W[4]) + (B[2] + B[3]);
  ans = min(ans, aux);
  cout << ans;
}
