#include <bits/stdc++.h>
using namespace std;
const long long N = 1000;
long long n, grid[N][N];
void run() {
  cin >> n;
  long long fill = 0;
  for (long long i = 0; i < n / 2; i++) {
    for (long long j = 0; j < n / 2; j++) {
      grid[i][j] = 4 * fill + 1;
      grid[i][j + n / 2] = 4 * fill + 2;
      grid[i + n / 2][j] = 4 * fill + 3;
      grid[i + n / 2][j + n / 2] = 4 * fill;
      fill++;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }
}
signed main() {
  long long tests = 1;
  for (long long i = 1; i <= tests; i++) run();
  return 0;
}
