#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int mat[2003][2003];
void solve() {
  long long int n;
  cin >> n;
  long long int a = 0;
  long long int k = 0;
  while (k < n) {
    long long int l = 0;
    while (l < n) {
      for (long long int i = 0; i < 4; i++) {
        for (long long int j = 0; j < 4; j++) {
          mat[k + i][l + j] = a++;
        }
      }
      l += 4;
    }
    k += 4;
  }
  long long int x = 0;
  for (long long int i = 0; i < n; i++) x = x ^ mat[0][i];
  for (long long int i = 0; i < n; i++) {
    long long int y = 0;
    for (long long int j = 0; j < n; j++) {
      cout << mat[i][j] << " ";
      y = y ^ mat[j][i];
    }
    cout << endl;
  }
}
signed main() {
  long long int t = 1;
  for (long long int tc = 1; tc <= t; tc++) {
    solve();
  }
}
