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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		long ix = 0;
		long iy = 0;
		long m = 2;
		long t = m;
		long h = 1;
		long[,]A = new long[500,500];
		long at = 2;
		while(true){
			if((ix+iy)%2==0){
				while(true){
					//if(IsPrime((int)at)){
						A[ix,iy]=at;
						at += 1;
						break;
					//} else {
					//	at += 1;
					//}
				}
			}
			ix += 1;
			if(ix>=500){
				iy = iy + 2;
				if(iy==500){
					iy = 1;
				}
				ix = 0;
			}
			if(iy==501){
				break;
			}
		}
		ix = 0;
		iy = 0;
		while(true){
			if((ix+iy)%2==1){
				long aa = 1;
				if(ix>0){
					aa = Lcm(aa,A[ix-1,iy]);
				}
				if(ix<500-1){
					aa = Lcm(aa,A[ix+1,iy]);
				}
				if(iy>0){
					aa = Lcm(aa,A[ix,iy-1]);
				}
				if(iy<500-1){
					aa = Lcm(aa,A[ix,iy+1]);
				}
				A[ix,iy] = aa+1;
			}
			ix += 1;
			if(ix>=500){
				iy += 1;
				ix = 0;
			}
			if(iy>=500){
				break;
			}
		}
		for(var i=0;i<N;i++){
			string str = "";
			str += A[0,i];
			for(var j=1;j<N;j++){
				str += " " + A[j,i];
			}
			Console.WriteLine(str);
		}
	}
	public static bool IsPrime(int num)
	{
		if (num < 2) return false;
		else if (num == 2) return true;
		else if (num % 2 == 0) return false;

		double sqrtNum = Math.Sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2){
			if (num % i == 0) return false;
		}
		return true;
	}
	public static long Lcm(long a, long b) {
        return a * b / Gcd(a, b);
    }
	public static long Gcd(long a, long b) {
		if (a < b)
			return Gcd(b, a);
		while (b != 0) {
			var r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
}