#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, cnt;
int mp[N][N];
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n / 2; i++)
    for (int j = 1; j <= n / 2; j++) {
      mp[i][j] = cnt * 4;
      mp[i][j + n / 2] = cnt * 4 + 1;
      mp[i + n / 2][j] = cnt * 4 + 2;
      mp[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 ", mp[i][j]);
    printf("\n");
  }
  return 0;
}
