#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using vvi = vector<vi>;
using vpi = vector<pair<long long, long long>>;
using pi = pair<long long, long long>;
const long long nax = 1e6 + 7;
const long long mod = 1e9 + 7;
const long long inf = numeric_limits<long long>::max() - (long long)9e6;
void test() {
  long long n;
  cin >> n;
  static long long counter = 0;
  vvi grid(n, vi(n));
  for (long long i = 0; i < n / 2; i++) {
    for (long long j = 0; j < n / 2; j++) {
      grid[i][j] = 4 * counter;
      grid[i][j + n / 2] = 4 * counter + 1;
      grid[i + n / 2][j] = 4 * counter + 2;
      grid[i + n / 2][j + n / 2] = 4 * counter + 3;
      counter++;
    }
  }
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = 0; j < (long long)n; j++) {
      cout << grid[i][j] << " ";
    }
    cout << '\n';
  }
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  while (T--) {
    test();
    cout << "\n";
  }
  return 0;
}
