#include <bits/stdc++.h>
using namespace std;
long long base[4][4] = {
    {8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};
vector<vector<long long>> res;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long N;
  cin >> N;
  long long s = N / 4;
  res.resize(N);
  for (long long i = 0; i < N; i++) {
    res[i].resize(N);
    for (long long j = 0; j < N; j++) {
      long long u = i % 4, v = j % 4, x = i / 4, y = j / 4;
      res[i][j] = (base[u][v] | ((x * s + y) << 4));
      cout << res[i][j] << " ";
    }
    cout << "\n";
  }
  cout.flush();
}
