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