#include <bits/stdc++.h>
using namespace std;
int mp[1005][1005], n;
int main() {
  while (~scanf("%d", &n)) {
    int cnt = n * n / 4;
    ;
    int l = 1, r = 1;
    for (int i = 0; i < cnt; ++i) {
      mp[l][r] = i * 4;
      mp[l][r + 1] = i * 4 + 1;
      mp[l + 1][r] = i * 4 + 2;
      mp[l + 1][r + 1] = i * 4 + 3;
      if (r == n - 1) {
        l += 2;
        r = 1;
      } else
        r += 2;
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) printf("%d ", mp[i][j]);
      printf("\n");
    }
  }
  return 0;
}
