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