#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1005;
long long a[maxn][maxn];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long h = n / 2;
  long long cur = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < h; j++) {
      a[i][j] = cur++;
      a[i + h][j] = cur++;
      a[i][j + h] = cur++;
      a[i + h][j + h] = cur++;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << '\n';
  }
}
