#include <bits/stdc++.h>
using namespace std;
template <class R>
inline void Readin(R &K) {
  bool F = K = 0;
  char C = getchar();
  while (C < '0' || C > '9') {
    if (C == '-') F = 1;
    C = getchar();
  }
  while (C <= '9' && C >= '0') K = (K << 1) + (K << 3) + C - '0', C = getchar();
  if (F) K = -K;
}
template <class R>
inline bool Checkmax(R &A, R B) {
  return A < B ? A = B, 1 : 0;
}
template <class R>
inline bool Checkmin(R &A, R B) {
  return A > B ? A = B, 1 : 0;
}
int N;
int Ans[1005][1005], Cnt;
int main() {
  Readin(N);
  int N_ = N;
  while (N_) {
    register int R = 1;
    while ((R << 1) <= N_) R <<= 1;
    for (register int i = 0; ++i <= N;)
      for (register int j = N - N_; ++j <= N - N_ + R;) Ans[i][j] = Cnt++;
    N_ -= R;
  }
  for (register int i = 0; ++i <= N;) {
    for (register int j = 0; ++j <= N;) printf("%d ", Ans[i][j]);
    printf("\n");
  }
  return 0;
}
