#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
long long int vis[N];
vector<long long int> adj[N];
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.first > b.first)
    return 1;
  else if (a.first == b.first)
    return (a.second < b.second);
  else
    return 0;
}
void solve() {
  long long int curr = 0;
  long long int n;
  cin >> n;
  long long int a[n][n];
  for (int i = 0; i < n / 2; i++) {
    for (int j = 0; j < n / 2; j++) {
      a[i][j] = 4 * (curr);
      a[n / 2 + i][j] = 4 * (curr) + 1;
      a[i][n / 2 + j] = 4 * (curr) + 2;
      a[n / 2 + i][n / 2 + j] = 4 * (curr) + 3;
      curr++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int Test;
  Test = 1;
  long long int t = 0;
  while (t++ < Test) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
