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 rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 500;

ll mat[N + 2][N + 2];
int n;

int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
	cin >> n;
	if(n == 2){
		cout << 4 << " " << 7 << "\n" << 23 << " " << 10 << "\n";
		return 0;
	}
	ll cnt = 123;
	rep(i, 0, n + 2){
		rep(j, 0, n + 2){
			mat[i][j] = 1;
		}
	}
	rep(i, 1, n + 1){
		rep(j, 1, n + 1){
			if((i ^ j) & 1){
				mat[i][j] = cnt++;	
			}
		}
	}
	rep(i, 1, n + 1){
		rep(j, 1, n + 1){
			if(!((i ^ j) & 1)){
				for(auto x : {mat[i - 1][j], mat[i + 1][j], mat[i][j - 1], mat[i][j + 1]}){
					mat[i][j] = (mat[i][j] * x) / __gcd(mat[i][j], x);
				}
				mat[i][j]++;
			}
		}
	}
  	rep(i, 1, n + 1){
		rep(j, 1, n + 1){
			cout << mat[i][j] << " \n"[j == n];
		}
	}
    return 0;
}