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