#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int dp[1025][1025];
int main() {
  int n;
  cin >> n;
  int d = 0;
  for (int i = 1; i <= n / 2; i++)
    for (int j = 1; j <= n / 2; j++) {
      dp[i][j] = d * 4 + 1;
      dp[i][j + n / 2] = d * 4 + 2;
      dp[i + n / 2][j] = d * 4 + 3;
      dp[i + n / 2][j + n / 2] = d * 4;
      d++;
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cout << dp[i][j] << ' ';
    cout << endl;
  }
}
