#include <bits/stdc++.h>
inline int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    ch = getchar();
    if (ch == '-') w = -1;
  }
  while (ch <= '9' && ch >= '0') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * w;
}
using namespace std;
const int N = 1005;
int n, tot;
int a[N][N];
int main() {
  n = read();
  for (int i = 1; i <= n; i += 2) {
    for (int j = 1; j <= n; j += 2) {
      a[i][j] = (tot << 2), ++tot;
      a[i][j + 1] = a[i][j] + 1;
      a[i + 1][j] = a[i][j] + 3;
      a[i + 1][j + 1] = a[i][j] + 2;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) printf("%d ", a[i][j]);
    puts("");
  }
  return 0;
}
