#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[1007][1007];
  long long max = n * n - 1;
  long long k = 1, p = 0;
  for (int i = 0; i < n / 2; i++) {
    for (int j = 0; j < n / 2; j++) {
      a[i][j] = k;
      k += 4;
    }
    for (int j = n / 2; j < n; j++) {
      a[i][j] = p;
      p += 4;
    }
  }
  k = 3, p = 2;
  for (int i = n / 2; i < n; i++) {
    for (int j = 0; j < n / 2; j++) {
      a[i][j] = k;
      k += 4;
    }
    for (int j = n / 2; j < n; j++) {
      a[i][j] = p;
      p += 4;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << a[i][j] << " ";
    cout << endl;
  }
}
