#include <bits/stdc++.h>
using namespace std;
const long long N = 1000 + 5;
long long n, a[N][N];
bool check() {
  long long val = -1;
  for (long long i = 0; i < n; ++i) {
    long long x = 0, y = 0;
    for (long long j = 0; j < n; ++j) x ^= a[i][j], y ^= a[j][i];
    if (val != -1 && x != val) return false;
    val = x;
    if (val != -1 && y != val) return false;
  }
  return true;
}
void init() { cin >> n; }
void solve() {
  long long k = 0;
  for (long long i = 0; i < n / 2; ++i) {
    for (long long j = 0; j < n / 2; ++j) {
      a[i][j] = k * 4;
      a[i + n / 2][j] = k * 4 + 1;
      a[i + n / 2][j + n / 2] = k * 4 + 2;
      a[i][j + n / 2] = k * 4 + 3;
      ++k;
    }
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < n; ++j) {
      cout << a[i][j] << (j == n - 1 ? '\n' : ' ');
    }
  }
}
int32_t main() {
  init();
  solve();
}
