Let us define a magic grid to be a square matrix of integers of size n × n, satisfying the following conditions. 

  * All integers from 0 to (n^2 - 1) inclusive appear in the matrix exactly once. 
  * [Bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all elements in a row or a column must be the same for each row and column. 



You are given an integer n which is a multiple of 4. Construct a magic grid of size n × n.

Input

The only line of input contains an integer n (4 ≤ n ≤ 1000). It is guaranteed that n is a multiple of 4.

Output

Print a magic grid, i.e. n lines, the i-th of which contains n space-separated integers, representing the i-th row of the grid.

If there are multiple answers, print any. We can show that an answer always exists.

Examples

Input


4


Output


8 9 1 13
3 12 7 5
0 2 4 11
6 10 15 14

Input


8


Output


19 55 11 39 32 36 4 52
51 7 35 31 12 48 28 20
43 23 59 15 0 8 16 44
3 47 27 63 24 40 60 56
34 38 6 54 17 53 9 37
14 50 30 22 49 5 33 29
2 10 18 46 41 21 57 13
26 42 62 58 1 45 25 61

Note

In the first example, XOR of each row and each column is 13.

In the second example, XOR of each row and each column is 60.
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")
using namespace std;
void print_width(long long x) {
  std::cout << std::fixed;
  std::cout << std::setprecision(x);
}
long long power(long long x, long long y, long long p = 1000000007) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void printArr(long long a[], long long n) {
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  cout << '\n';
}
void printVector(std::vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << '\n';
}
void printVectorPair(std::vector<pair<long long, long long>> v) {
  for (long long i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << '\n';
  ;
  cout << '\n';
}
void initialize(long long arr[], long long n) {
  for (long long i = 0; i <= n; i++) arr[i] = i;
}
long long root(long long arr[], long long i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void Union(long long arr[], long long a, long long b) {
  long long root_a = root(arr, a);
  long long root_b = root(arr, b);
  arr[root_a] = root_b;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power_wm(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
std::vector<long long> vsum(std::vector<long long> a) {
  std::vector<long long> s(a.size());
  s[0] = a[0];
  for (long long i = 1; i <= a.size() - 1; i++) {
    s[i] = s[i - 1] + a[i];
  }
  return s;
}
void time() {}
long long sti(string s) {
  long long ans = 0;
  long long p = 1;
  for (long long i = s.size() - 1; i >= 0; i--) {
    ans = (ans + ((long long)(s[i] - '0') * p) % 1000000007) % 1000000007;
    p = (p * 10) % 1000000007;
  }
  return ans;
}
long long bfs(long long x, long long y, vector<vector<long long>> &g) {
  std::vector<long long> vis(100001, 0);
  vis[x] = 1;
  queue<long long> q;
  q.push(x);
  std::vector<long long> level(100001, (long long)1e18);
  level[x] = 0;
  while (!q.empty()) {
    long long p = q.front();
    q.pop();
    for (long long i = 0; i < g[p].size(); i++) {
      long long p2 = g[p][i];
      if (vis[p2] == 0) {
        if (x == p and y == p2) {
          continue;
        } else {
          q.push(p2);
          vis[p2] = 1;
          level[p2] = level[p] + 1;
        }
      }
    }
  }
  return level[y];
}
string multiply(string num1, string num2) {
  long long len1 = num1.size();
  long long len2 = num2.size();
  if (len1 == 0 || len2 == 0) return "0";
  vector<long long> result(len1 + len2, 0);
  long long i_n1 = 0;
  long long i_n2 = 0;
  for (long long i = len1 - 1; i >= 0; i--) {
    long long carry = 0;
    long long n1 = num1[i] - '0';
    i_n2 = 0;
    for (long long j = len2 - 1; j >= 0; j--) {
      long long n2 = num2[j] - '0';
      long long sum = n1 * n2 + result[i_n1 + i_n2] + carry;
      carry = sum / 10;
      result[i_n1 + i_n2] = sum % 10;
      i_n2++;
    }
    if (carry > 0) result[i_n1 + i_n2] += carry;
    i_n1++;
  }
  long long i = result.size() - 1;
  while (i >= 0 && result[i] == 0) i--;
  if (i == -1) return "0";
  string s = "";
  while (i >= 0) s += std::to_string(result[i--]);
  return s;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long mat[n][n];
  long long p = 0;
  for (long long i = 0; i < n; i += 4) {
    for (long long j = 0; j < n; j += 4) {
      for (long long a = i; a < i + 4; a++) {
        for (long long b = j; b < j + 4; b++) {
          mat[a][b] = p;
          p++;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << mat[i][j] << " ";
    }
    cout << '\n';
  }
  return 0;
}
