#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int n;
  cin >> n;
  int a[n][n];
  n /= 2;
  for (int rg = 0; rg < n; rg++) {
    int rgn = rg * n;
    for (int cg = 0; cg < n; cg++) {
      int fill = (rgn + cg) << 2;
      int r = rg << 1, c = cg << 1;
      if ((rg + cg) & 1) {
        a[r][c] = fill;
        a[r][c + 1] = fill + 2;
        a[r + 1][c] = fill + 1;
        a[r + 1][c + 1] = fill + 3;
      } else {
        a[r][c] = fill;
        a[r][c + 1] = fill + 1;
        a[r + 1][c] = fill + 2;
        a[r + 1][c + 1] = fill + 3;
      }
    }
  }
  n *= 2;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << a[i][j] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
