#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
int a[maxn][maxn];
int n;
void solve() {
  int l = 0, r = 0;
  for (int i = 0; i < n * n; i += 2) {
    a[l][r] = i;
    if (r == n - 1) {
      r = 0;
      l += 2;
    } else
      r++;
  }
  l = 1;
  r = 0;
  for (int i = 1; i < n * n; i += 2) {
    a[l][r] = i;
    if (r == n - 1) {
      r = 0;
      l += 2;
    } else
      r++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      printf("%d ", a[i][j]);
    }
    printf("\n");
  }
}
int main() {
  scanf("%d", &n);
  solve();
  return 0;
}
