#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
unsigned long long int pow1(unsigned long long int a, unsigned long long int b,
                            unsigned long long int c) {
  unsigned long long int ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= c;
    }
    b /= 2;
    a = a * a;
    a %= c;
  }
  return ans;
}
long long int gcd(unsigned long long int a, unsigned long long int b) {
  unsigned long long int t = a;
  a = min(a, b);
  b = max(b, t);
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
unsigned long long int fct(unsigned long long int k) {
  unsigned long long int a = 1;
  for (long long int i = 2; i < k + 1; i++) {
    a *= i;
    a %= 1000000007;
  }
  return a;
}
unsigned long long int C(unsigned long long int n, unsigned long long int r) {
  if (n < r)
    return 0;
  else if (n == r || r == 0)
    return 1;
  vector<vector<unsigned long long int> > v(
      n + 1, vector<unsigned long long int>(r + 1));
  for (long long int i = 0; i < n + 1; i++) v[i][0] = 1;
  for (long long int i = 0; i < r + 1; i++) v[0][i] = 1;
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < min(i, (long long int)r) + 1; j++) {
      if (i == j)
        v[i][j] = 1;
      else if (j == 1)
        v[i][j] = i;
      else
        v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]) % 1000000007;
    }
  }
  return v[n][r] % 1000000007;
}
char ass(char a) {
  if (a == 'a' || a == 'c') return 'b';
  return 'a';
}
char assn(char a, char b) {
  if (a == 'a') {
    if (b == 'b')
      return 'c';
    else
      return 'b';
  } else if (a == 'b') {
    if (b == 'a')
      return 'c';
    else
      return 'a';
  } else {
    if (b == 'a')
      return 'b';
    else
      return 'a';
  }
}
pair<long long int, long long int> solv(long long int ps, long long int s,
                                        long long int pw, long long int w,
                                        long long int p) {
  long long int a = ps, b = pw;
  ps /= 2;
  pw /= 2;
  long long int ans1 = ps * s + pw * w;
  long long int ps1 = -1, ps2 = -1;
  if (max(a, b) <= (ps + 1 + pw) && (ps + 1) * s + pw * w <= p) {
    ans1 = (ps + 1) * s + pw * w;
    ps1 = ps + 1;
    ps2 = pw;
  }
  if (max(a, b) <= (ps + pw + 1) && (ps)*s + (1 + pw) * w <= p) {
    ans1 = (ps)*s + (1 + pw) * w;
    ps2 = pw + 1;
    ps1 = ps;
  }
  if (max(a, b) <= (ps + pw + 2) && (ps + 1) * s + (1 + pw) * w <= p) {
    ans1 = (ps + 1) * s + (1 + pw) * w;
    ps1 = ps + 1;
    ps2 = pw + 1;
  }
  if (ps1 == -1) {
    if (a > b)
      return make_pair(a, 0);
    else if (a == b) {
      if (s > w) return make_pair(a, 0);
    }
    return make_pair(0, b);
  }
  return make_pair(ps1, ps2);
}
vector<int> adj[100000];
long long int cost[100000];
long long int c;
void dfs(int S, set<int>& st) {
  if (st.count(S)) {
    st.erase(S);
    c = min(c, cost[S]);
    for (auto& x : adj[S]) {
      if (st.count(x)) dfs(x, st);
    }
  }
}
int fn(vector<vector<char> > v, int n, char c) {
  int cnt = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (v[i][j] != c) cnt++;
      if (c == '1')
        c = '0';
      else
        c = '1';
    }
  }
  return cnt;
}
int drv(vector<vector<char> > a[4], int n) {
  int ans = 100000;
  int b[24] = {0, 1, 2, 3, 0, 2, 1, 3, 0, 3, 1, 2,
               1, 2, 3, 0, 1, 3, 2, 0, 2, 3, 1, 0};
  for (int i = 0; i < 24; i += 4) {
    ans = min(ans, fn(a[b[i]], n, '0') + fn(a[b[i + 1]], n, '0') +
                       fn(a[b[i + 2]], n, '1') + fn(a[b[i + 3]], n, '1'));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<vector<char> > a[4];
  for (long long int i = 0; i < 4; i++) {
    vector<vector<char> > v(n);
    a[i] = v;
    for (long long int j = 0; j < n; j++) {
      for (long long int k = 0; k < n; k++) {
        char c;
        cin >> c;
        a[i][j].push_back(c);
      }
    }
  }
  cout << drv(a, n);
}
