#include <bits/stdc++.h>
using namespace std;
string graph[4][100];
int cost[4][2];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    string graph1[n];
    for (int j = 0; j < n; j++) {
      cin >> graph[i][j];
      graph1[j] = graph[i][j];
    }
    if (graph1[0][0] == '1') {
      graph1[0][0] = '0';
      cost[i][0]++;
    }
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (j == 0 && k == 0) continue;
        char prethoden;
        if (k == 0)
          prethoden = graph1[j - 1][0];
        else
          prethoden = graph1[j][k - 1];
        char segasen;
        if (prethoden == '1')
          segasen = '0';
        else
          segasen = '1';
        if (graph1[j][k] != segasen) {
          graph1[j][k] = segasen;
          cost[i][0]++;
        }
      }
    }
    for (int j = 0; j < n; j++) {
      graph1[j] = graph[i][j];
    }
    if (graph1[0][0] == '0') {
      graph1[0][0] = '1';
      cost[i][1]++;
    }
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (j == 0 && k == 0) continue;
        char prethoden;
        if (k == 0)
          prethoden = graph1[j - 1][0];
        else
          prethoden = graph1[j][k - 1];
        char segasen;
        if (prethoden == '1')
          segasen = '0';
        else
          segasen = '1';
        if (graph1[j][k] != segasen) {
          graph1[j][k] = segasen;
          cost[i][1]++;
        }
      }
    }
  }
  long long min_cost = LLONG_MAX;
  for (int mask = 0; mask < 16; mask++) {
    if (__builtin_popcount(mask) == 2) {
      long long cst = 0;
      for (int i = 0; i < 4; i++) {
        int idx;
        if ((mask & (1 << i)) != 0)
          idx = 1;
        else
          idx = 0;
        cst += cost[i][idx];
      }
      min_cost = min(min_cost, cst);
    }
  }
  cout << min_cost << endl;
  return 0;
}
