#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  cin >> n;
  t = n / 4;
  for (int m = 0; m < t; m++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < t; k++) {
        for (int i = 0 + 4 * j; i < 4 + 4 * j; i++) {
          cout << i + k * 16 + t * 16 * m << " ";
        }
      }
      cout << endl;
    }
  }
  return 0;
}
