#include <bits/stdc++.h>
using namespace std;
inline long long rint() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return (b) ? gcd(b, a % b) : a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long pow(long long a, long long b, long long q) {
  long long rtn = 1;
  while (b) {
    if (b & 1) rtn = rtn * a % q;
    a = a * a % q;
    b >>= 1;
  }
  return rtn;
}
inline long long mysqrt(long long n) {
  long long x = sqrt(n);
  while (x * x < n) x++;
  while (x * x > n) x--;
  return x;
}
const long long mod = 1e9 + 7;
int res[1005][1005];
int main() {
  int n = rint() / 4;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int a = i * 4; a < i * 4 + 4; a++) {
        for (int b = j * 4; b < j * 4 + 4; b++) {
          res[a][b] = cnt++;
        }
      }
    }
  }
  for (int i = 0; i < n * 4; i++) {
    for (int j = 0; j < n * 4; j++) cout << res[i][j] << " ";
    cout << "\n";
  }
}
