#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, a1, b1, c1, d1;
int main() {
  long long n;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i % 2 == 0) {
        if (j % 2 == 0) {
          if (s[i][j] == '0')
            a++;
          else
            a1++;
        }
        if (j % 2 == 1) {
          if (s[i][j] == '1')
            a++;
          else
            a1++;
        }
      } else {
        if (j % 2 == 0) {
          if (s[i][j] == '1')
            a++;
          else
            a1++;
        }
        if (j % 2 == 1) {
          if (s[i][j] == '0')
            a++;
          else
            a1++;
        }
      }
    }
  }
  string s2[n];
  for (int i = 0; i < n; i++) cin >> s2[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i % 2 == 0) {
        if (j % 2 == 0) {
          if (s2[i][j] == '0')
            b++;
          else
            b1++;
        }
        if (j % 2 == 1) {
          if (s2[i][j] == '1')
            b++;
          else
            b1++;
        }
      } else {
        if (j % 2 == 0) {
          if (s2[i][j] == '1')
            b++;
          else
            b1++;
        }
        if (j % 2 == 1) {
          if (s2[i][j] == '0')
            b++;
          else
            b1++;
        }
      }
    }
  }
  string s3[n];
  for (int i = 0; i < n; i++) cin >> s3[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i % 2 == 0) {
        if (j % 2 == 0) {
          if (s3[i][j] == '0')
            c++;
          else
            c1++;
        }
        if (j % 2 == 1) {
          if (s3[i][j] == '1')
            c++;
          else
            c1++;
        }
      } else {
        if (j % 2 == 0) {
          if (s3[i][j] == '1')
            c++;
          else
            c1++;
        }
        if (j % 2 == 1) {
          if (s3[i][j] == '0')
            c++;
          else
            c1++;
        }
      }
    }
  }
  string s4[n];
  for (int i = 0; i < n; i++) cin >> s4[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i % 2 == 0) {
        if (j % 2 == 0) {
          if (s4[i][j] == '0')
            d++;
          else
            d1++;
        }
        if (j % 2 == 1) {
          if (s4[i][j] == '1')
            d++;
          else
            d1++;
        }
      } else {
        if (j % 2 == 0) {
          if (s4[i][j] == '1')
            d++;
          else
            d1++;
        }
        if (j % 2 == 1) {
          if (s4[i][j] == '0')
            d++;
          else
            d1++;
        }
      }
    }
  }
  long long m = INT_MAX;
  m = min(a + b + c1 + d1, m);
  m = min(a + b1 + c + d1, m);
  m = min(a + b1 + c1 + d, m);
  m = min(a1 + b + c + d1, m);
  m = min(a1 + b + c1 + d, m);
  m = min(a1 + b1 + c + d, m);
  cout << m;
}
