Universal Cup Judging System

Universal Cup

Limite de temps : 3.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓
Statistiques

You are given a positive even integer $n$. Consider an $n\times n$ grid whose rows and columns are both numbered from $1$ to $n$. The cell in row $r$ and column $c$ is denoted $(r,c)$.

Your task is to arrange all $n^2$ cells of the grid into a sequence $p_1,p_2,\ldots,p_{n^2}$ in which every cell appears exactly once such that, with the convention $p_{n^2+1}=p_1$, for every $i$ from $1$ to $n^2$, the cells $p_i$ and $p_{i+1}$ lie in the same row or in the same column and satisfy

$$ |r_i-r_{i+1}|+|c_i-c_{i+1}|=((i-1)\bmod 4)+1, $$

where $p_i=(r_i,c_i)$ and $p_{i+1}=(r_{i+1},c_{i+1})$.

In other words, the sequence should be a closed tour of length $n^2$ visiting every cell once, each move is horizontal or vertical, and the move lengths form a sequence $1,2,3,4,1,2,3,4,\ldots$ repeating cyclically, including the final move from $p_{n^2}$ back to $p_1$.

If such a sequence exists, output any one of them.

Input

The first line contains a single even integer $n$ ($4\le n\le 200$).

Output

If no valid sequence exists, print a single line containing NO.

Otherwise, print YES on the first line, and then print $n$ lines containing $n$ integers each. The $j$-th column of the $i$-th row should contain one integer $k$ such that, in your answer, $p_k$ is the cell $(i,j)$.

If there are multiple valid answers, print any one of them.

Examples

Input 1

8

Output 1

YES
1 7 25 26 8 27 37 38
2 60 23 33 59 48 42 41
5 6 16 34 57 46 45 39
3 21 22 52 58 28 43 53
64 19 24 35 9 47 36 54
62 61 15 32 10 49 31 40
4 18 17 51 56 50 44 55
63 20 14 13 11 29 30 12

Note

problem_20738_835e5d6b7f5c02dfde4059f56720a65b.png

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.