#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  int grid[1001][1001];
  int num = 0;
  for (int i = 0; i < n / 2; i++) {
    for (int j = 0; j < n / 2; j++) {
      grid[i][j] = 4 * num;
      grid[i][j + n / 2] = 4 * num + 1;
      grid[i + n / 2][j] = 4 * num + 2;
      grid[i + n / 2][j + n / 2] = 4 * num + 3;
      num++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << grid[i][j] << ' ';
    }
    cout << endl;
  }
}
int main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
