#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ar[1001][1001];
  cin >> n;
  int a = n / 2, v = 0;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < a; j++) {
      ar[i][j] = v++;
    }
  }
  v = 0;
  for (int i = 0; i < a; i++) {
    for (int j = a; j < n; j++) {
      ar[i][j] = v++;
    }
  }
  v = 0;
  for (int i = a; i < n; i++) {
    for (int j = 0; j < a; j++) {
      ar[i][j] = v++;
    }
  }
  v = 0;
  for (int i = a; i < n; i++) {
    for (int j = a; j < n; j++) {
      ar[i][j] = v++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ar[i][j] *= 4;
    }
  }
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < a; j++) {
      ar[i][j] += 3;
      ar[i + a][j] += 2;
      ar[i][j + a] += 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << ar[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
