Camel

Construct a closed knight-like tour for a jumping camel piece on an N x N board where N is a multiple of 5, printing the visit order or NO.

Hard8GreedyImplementationMathSimulationNo attempts yetTime limit2sMemory limit512 MB

Problem

Define a new chess piece called camel-tone. It jumps two squares orthogonally to land three squares away, or one square diagonally to land two squares away. That is, from (r,c)(r, c) it can move to (r±3,c)(r \pm 3, c), (r,c±3)(r, c \pm 3), or (r±2,c±2)(r \pm 2, c \pm 2), whenever the destination lies on the board. There are 8 possible moves in total.

The board is a square of N×NN \times N cells, where NN is always a multiple of 5.

The piece starts on the top-left corner cell (row 1, column 1). Play consists of a sequence of moves that visits every cell exactly once, and after N21N^2 - 1 moves the piece is exactly one move away from its starting cell. Such a closed tour is called a camel-tone cycle.

Write a program camel that finds any such tour, or reports that the cycle is impossible.

Input

One line is read from standard input, containing a single integer NN.

Output

Write one of the following to standard output.

  • If the cycle is impossible, print NO on one line.

  • Otherwise, print NN lines. Each line contains NN space-separated integers. These integers are the distinct integers from 11 to N2N^2. The first number of the first line is 11. The output represents the board, and each integer gives the visit order of its cell. The cells holding two consecutive numbers are one piece move apart, and the cell holding N2N^2 is one move away from the start cell holding 11.

Constraints

  • NN is a multiple of 5.
  • 5N10005 \le N \le 1000.

Hint

Each number in the output is the visit order of its cell. The cells holding kk and k+1k + 1 are always one piece move apart, and so are the cells holding N2N^2 and 11. The starting cell is always the top-left corner with value 11.