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