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<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
int main(){
	int N;
	ll a[501][501];
	scan(N);
	if(N>=5) return 0;
	for(ll mod=1;mod<=1e+3;mod++){
		ll usedmax=0;
		int flag=1;
		map<ll,ll> used;
		rep(j,N){
			rep(i,N){
				if(j){
					if(i){
						ll bigtonari=max(a[i-1][j],a[i][j-1]);
						ll smalltonari=min(a[i-1][j],a[i][j-1]);
						ll koubaisu=lcm(a[i-1][j],a[i][j-1]);
						ll karia=smalltonari+mod;
						while(1){
							if(karia>1e+15||karia<=0){
								flag=0;
								break;
							}
							//printf("j:%d i:%d karia:%lld\n",j,i,karia);
							if(used[karia]==0){
								if(karia>bigtonari){
									if(karia%bigtonari==mod&&karia%smalltonari==mod) break;
									else karia=koubaisu+mod;
								}
								else{
									if(bigtonari%karia==mod&&karia%smalltonari==mod) break;
									else karia+=smalltonari;
								}
							}
							else{
								if(karia>bigtonari){
									karia+=koubaisu;
								}
								else{
									karia+=smalltonari;
								}
							}
						}
						a[i][j]=karia;
						used[a[i][j]]=1;
					}
					else{
						ll karia=a[i][j-1]+mod;
						while(used[karia]!=0){
							karia+=a[i][j-1];
						}
						a[i][j]=karia;
						used[a[i][j]]=1;
					}
				}
				else{
					a[i][j]=mod*(i+1)+1;
					used[a[i][j]]=1;
				}
				//printf("j:%d i:%d a[i][j]:%lld\n",j,i,a[i][j]);
				usedmax=max(usedmax,a[i][j]);
				if(usedmax>=1e+15||a[i][j]<=0){
					flag=0;
					break;
				}

				if(j==N-1&&i==N-1) flag=-1;
			}
			if(flag==0) break;
		}
		//if(mod==1) break;
		if(flag==-1) break;
	}
	rep(i,N){
		rep(j,N){
			printf("%lld ",a[i][j]);
		}
		kaigyo;
	}
	return 0;
}