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 Ruby (2.3.3) (judge verdict: Accepted)

require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end


def gcd(a,b)
	if(a>b)
		return gcd(b,a)
	end
	while(b%a != 0)
		tmp = a
		a = b%a
		b = tmp
	end
	return a
end
def lcm(a,b)
	a/gcd(a,b)*b
end


N,_=gets.chomp.split(' ').map{|n| n.to_i}

A=Array.new(N) { |i| Array.new(N) {1} }

P=Array.new(100001) {true}
P[0]=P[1]=false
for i in 2..(100000)
	if(P[i])
		(i+i).step(100000, i){|j|
			P[j] = false
		}
	end
end
@pi = 0
def get
	@pi += 1
	while(!P[@pi])
		@pi += 1
	end
	@pi
end

0.step(2*N-2,2){|n|
	val = get
	dputs "left down line #{val}"
	for i in 0..n
		j = n-i
		if(0<=i && i<N && 0<=j && j<N)
			A[i][j] *= val
		end
	end
}
val = get
dputs "right down line #{val}"
for i in 0..(N-1)
	j = i
	if(0<=i && i<N && 0<=j && j<N)
		A[i][j] *= val
	end
end
2.step(N-1,2){|d|
	val = get
	dputs "right down line #{val}"
	for i in 0..(N-1)
		j = i+d
		if(0<=i && i<N && 0<=j && j<N)
			A[i][j] *= val
		end
	end
	val = get
	dputs "right down line #{val}"
	for i in 0..(N-1)
		j = i-d
		if(0<=i && i<N && 0<=j && j<N)
			A[i][j] *= val
		end
	end
}
for i in 0..(N-1)
	for j in 0..(N-1)
		if(A[i][j]==1)
			nei = []
			nei << A[i-1][j] if(i>0)
			nei << A[i+1][j] if(i<N-1)
			nei << A[i][j-1] if(j>0)
			nei << A[i][j+1] if(j<N-1)
			A[i][j] = nei.inject(1){|a,sum| lcm(sum,a)} + 1
		end
	end
end
if(N==2)
	A[1][0] = (A[1][0] - 1) * 2 + 1
end

puts A.map{|a| a.join(" ")}.join("\n")