#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
const long long M = 1000000007;
long long pow1(long long a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % M;
    }
    a = (a * a) % M;
    b >>= 1;
  }
  return res % M;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  T = 1;
  while (T--) {
    long long n;
    cin >> n;
    long long ans[n][n];
    long long num = 0;
    for (long long i = 0; i < n; i++) {
      if (i % 2 == 1) {
        num = ans[0][i - 1] + 1;
      } else {
        num = n * (i);
      }
      long long num1 = num;
      for (long long j = 0; j < n; j++) {
        ans[j][i] = num1;
        num1 += 2;
      }
    }
    set<long long> se;
    for (long long i = 0; i < n; i++) {
      long long num = 0;
      for (long long j = 0; j < n; j++) num = num ^ ans[i][j];
      se.insert(num);
    }
    for (long long i = 0; i < n; i++) {
      long long num = 0;
      for (long long j = 0; j < n; j++) num = num ^ ans[j][i];
      se.insert(num);
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) cout << ans[i][j] << " ";
      cout << endl;
    }
  }
}
