Codeforces Round 125 (Div. 1)
D
Cube Snake
Codeforces
2700
原题
← CE →
翻译中…

You've got an $*n* × *n* × *n*$ cube, split into unit cubes. Your task is to number all unit cubes in this cube with positive integers from $1$ to $*n*^{3}$ so that:

翻译中…
  • each number was used as a cube's number exactly once;
  • for each $1 ≤ *i* < *n*^{3}$, unit cubes with numbers $*i*$ and $*i* + 1$ were neighbouring (that is, shared a side);
  • for each $1 ≤ *i* < *n*$ there were at least two different subcubes with sizes $*i* × *i* × *i*$, made from unit cubes, which are numbered with consecutive numbers. That is, there are such two numbers $*x*$ and $*y*$, that the unit cubes of the first subcube are numbered by numbers $*x*$, $*x* + 1$, $...$, $*x* + *i*^{3} - 1$, and the unit cubes of the second subcube are numbered by numbers $*y*$, $*y* + 1$, $...$, $*y* + *i*^{3} - 1$.
翻译中…

Find and print the required numeration of unit cubes of the cube.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 50$) — the size of the cube, whose unit cubes need to be numbered.

翻译中…

Output

翻译中…

Print all layers of the cube as $*n*$ $*n* × *n*$ matrices. Separate them with new lines. Print the layers in the order in which they follow in the cube. See the samples for clarifications.

翻译中…

It is guaranteed that there always is a solution that meets the conditions given in the problem statement.

翻译中…

Note

翻译中…

In the sample the cubes with sizes $2 × 2 × 2$ are numbered with integers $1, ..., 8$ and $5, ..., 12$.

翻译中…

样例

Input #1
3
Output #1
1 4 17
2 3 18
27 26 19

8 5 16
7 6 15
24 25 20

9 12 13
10 11 14
23 22 21
InputCopy OutputCopy
题目信息
题号
198D
时间限制
2 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。