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