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;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		int ix = 0;
		int iy = 0;
		long m = 2;
		long t = m;
		long h = 1;
		long[,]A = new long[500,500];
		int[,]B = new int[500,500];
		int[,]C = new int[500,500];
		long at = 0;
		var list = GeneratePrime(10000);
		while(true){
			if((ix+iy)%2==0){
				B[ix,iy] = 249+(ix-iy)/2;
				C[ix,iy] = 500;
				if(ix+iy>500){
					C[ix,iy] = ((ix+iy)-500)/2*2+499;
				} else if(ix+iy<500){
					C[ix,iy] = (500-(ix+iy))/2*2+500;
				}
				A[ix,iy]=(long)B[ix,iy] * (long)C[ix,iy];
			}
			ix += 1;
			if(ix>=500){
				iy += 1;
				ix = 0;
				if(iy==500){
					break;
				}
			}
		}
		ix = 0;
		iy = 0;
		while(true){
			if((ix+iy)%2==1){
				long aa = 1;
				if(ix==0){
					if(iy<499){
						aa *= B[ix,iy+1];
					}
				} else {
					aa *= B[ix-1,iy];
				}
				if(ix==499){
					if(iy>0){
						aa *= B[ix,iy-1];
					}
				} else {
					aa *= B[ix+1,iy];
				}
				if(ix==499){
					if(iy<499){
						aa *= C[ix,iy+1];
					}
				} else {
					aa *= C[ix+1,iy];
				}
				if(ix==0){
					if(iy>0){
						aa *= C[ix,iy-1];
					}
				} else {
					aa *= C[ix-1,iy];
				}
				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 List<int> GeneratePrime(int max)
	{
		System.Diagnostics.Debug.Assert(max >= 2);
		int prime;
		double sqrtMax = Math.Sqrt(max);
		var primeList = new List<int>();
		var searchList = Enumerable.Range(2, max - 1).ToList();
		do
		{
			prime = searchList.First();
			primeList.Add(prime);
			searchList.RemoveAll(n => n % prime == 0);
		} while (prime < sqrtMax);
		primeList.AddRange(searchList);
		return primeList;
	}
}