#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int M[n][n];
  int c = 0;
  for (int i = 0; i < n / 2; i++) {
    for (int l = 0; l < n / 2; l++) {
      M[i][l] = 4 * c + 1;
      M[i][l + n / 2] = 4 * c + 2;
      M[i + n / 2][l] = 4 * c + 3;
      M[i + n / 2][l + n / 2] = 4 * c;
      c++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int l = 0; l < n; l++) {
      cout << M[i][l] << " ";
    }
    cout << endl;
  }
  return 0;
}
