#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<ll>> solve(ll n) {
  ll next = 0;
  vector<vector<ll>> G(n, vector<ll>(n, 0));
  for (ll r = 0; r < n / 2; r++) {
    for (ll c = 0; c < n / 2; c++) {
      G[r][c] = next * 4;
      G[r][c + n / 2] = next * 4 + 1;
      G[r + n / 2][c] = next * 4 + 2;
      G[r + n / 2][c + n / 2] = next * 4 + 3;
      next++;
    }
  }
  for (ll r = 0; r < n; r++) {
    ll sum = 0;
    for (ll c = 0; c < n; c++) {
      sum ^= G[r][c];
    }
    assert(sum == 0);
  }
  for (ll c = 0; c < n; c++) {
    ll sum = 0;
    for (ll r = 0; r < n; r++) {
      sum ^= G[r][c];
    }
    assert(sum == 0);
  }
  return G;
}
int main() {
  ll n;
  cin >> n;
  assert(n % 4 == 0);
  vector<vector<ll>> G = solve(n);
  for (ll r = 0; r < n; r++) {
    for (ll c = 0; c < n; c++) {
      cout << G[r][c];
      if (c == n - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}
