#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int a[maxn][maxn];
int main() {
  int n;
  cin >> n;
  int tmp = 0;
  for (int i = 1; i <= n / 2; i++) {
    for (int j = 1; j <= n / 2; j++) {
      a[i][j] = 4 * tmp;
      a[i][j + n / 2] = 4 * tmp + 1;
      a[i + n / 2][j] = 4 * tmp + 2;
      a[i + n / 2][j + n / 2] = 4 * tmp + 3;
      tmp++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
