#include <bits/stdc++.h>
using namespace std;
int n, a[1010][1010];
int main() {
  scanf("%d", &n);
  int cur = 0;
  for (int i = 1; i <= n; i += 2) {
    for (int j = 1; j <= n; j += 2) {
      a[i][j] = cur + 1, a[i][j + 1] = cur;
      a[i + 1][j] = cur + 2, a[i + 1][j + 1] = cur + 3;
      cur += 4;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      printf("%d ", a[i][j]);
    }
    printf("\n");
  }
  return 0;
}
