#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 1005;
int n, row[N], col[N], p[N * N], a[N][N];
int main() {
  cin >> n;
  int ptr = 0;
  for (int i = 1; i <= n; i += 4) {
    for (int j = 1; j <= n; j += 4) {
      for (int x = i; x < i + 4; x++) {
        for (int y = j; y < j + 4; y++) {
          a[x][y] = ptr++;
          row[x] ^= a[x][y];
          col[y] ^= a[x][y];
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) printf("%d ", a[i][j]);
    puts("");
  }
  return 0;
}
