#ARC149C. [ARC149C] Avoid Prime Sum

[ARC149C] Avoid Prime Sum

Score : 500500 points

Problem Statement

You are given a positive integer NN.

Fill each square of a grid with NN rows and NN columns by writing a positive integer not greater than N2N^2 so that all of the following conditions are satisfied.

  • Two positive integers written in horizontally or vertically adjacent squares never sum to a prime number.
  • Every positive integer not greater than N2N^2 is written in one of the squares.

Under the Constraints of this problem, it can be proved that such a way to fill the grid always exists.

Constraints

  • 3N10003\leq N\leq 1000

Input

The input is given from Standard Input in the following format:

NN

Output

Print a way to fill the grid under the conditions in the following format, where AijA_{ij} is the positive integer at the ii-th row and jj-th column:

A11A_{11} \ldots A1NA_{1N}

\vdots

AN1A_{N1} \ldots ANNA_{NN}

If there are multiple ways to fill the grid under the conditions, any of them will be accepted.

4
15 11 16 12
13 3 6 9
14 7 8 1
4 2 10 5

In this grid, every positive integer from 11 through 1616 is written once. Additionally, among the sums of two positive integers written in horizontally or vertically adjacent squares are 15+11=2615+11=26, 11+16=2711+16=27, and 15+13=2815+13=28, none of which is a prime number.