Problem:
Score : 1100 points

Problem Statement

You are given an integer N.

Construct any one N-by-N matrix a that satisfies the conditions below. It can be proved that a solution always exists under the constraints of this problem.

1 \leq a_{i,j} \leq 10^{15}

a_{i,j} are pairwise distinct integers.

There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.

Constraints

2 \leq N \leq 500

Input

Input is given from Standard Input in the following format:

N

Output

Print your solution in the following format:

a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}

Sample Input 1

2

Sample Output 1

4 7
23 10

For any two elements x and y that are vertically or horizontally adjacent, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always 3.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

////////////////////////////////////////////////////////////////////

ll l2(ll m){
	ll k=0;
if(m>=2){
m/=2;
k++;
}
else{
	return k;
}

}


int main() {
ll n;
cin>>n;
ll a[501][501];


for(int i=0;i<=500;i++){
	for(int j=0;j<=500;j++){
		a[i][j]=0;
	}
}

ll pow2[50];
pow2[0]=1;
for(int i=1;i<=49;i++){
pow2[i]=pow2[i-1]*2;
}

ll m;
ll r;

m=1000000000000;
r=1;

cout<<pow2[1]<<endl;

for(int i=1;i<=500;i++){
	
if(i==1){
	a[i][1]=m;
	continue;
}
for(int j=1;j<=49;j++){
	if(i==pow2[j]){
		if(j==1){
			a[i][1]=2*m+r;
		}
		else{
		a[i][1]=pow2[j]*m+pow(2,j*2-2)*r+r;}

		break;
		}
		
}

if(a[i][1]==0)
a[i][1]=a[i-1][1]+r;




	}

for(int i=1;i<=500;i++){
	for(int j=2;j<=500;j++){
a[i][j]=a[i][j-1]+pow(2,l2(i))*r;

	}
}

for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
		if(j<=n-1){
		cout<<a[i][j]<<" ";}
		else{
			cout<<a[i][j]<<endl;}
		
	}
	
}

return 0;

}