#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<vector<int> > ans(n, vector<int>(n));
  int start = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = start, idx = 0; idx < n; j += 4, idx++) ans[i][idx] = j;
    if ((i + 1) % 4 == 0) {
      start = n * (i + 1);
    } else {
      start++;
    }
  }
  set<int> x0rs;
  for (int i = 0; i < n; ++i) {
    int x0r = 0;
    for (int j = 0; j < n; ++j) {
      x0r ^= ans[i][j];
    }
    x0rs.insert(x0r);
    x0r = 0;
    for (int j = 0; j < n; ++j) {
      x0r ^= ans[j][i];
    }
    x0rs.insert(x0r);
  }
  cerr << "x0rs:" << endl;
  for (int el : x0rs) {
    cerr << el << " ";
  }
  cerr << endl;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
