#B4199. Spiral Filling of a Number Square

    ID: 11856 Type: Default 1000ms 256MiB

Spiral Filling of a Number Square

Spiral Filling of a Number Square

Renowned archaeologist X from city C has discovered an ancient palace in the desert. At the palace's entrance, he found two mysterious number squares. After some thought, he deduced the secret: fill an n×n square with numbers in increasing order by filling its outer layers one by one. For each layer, starting at the top‐left corner, alternate between clockwise and anticlockwise filling. The first outer layer is filled clockwise, the next anticlockwise, then clockwise, and so on.

As his assistant, your task is to fill a given n×n blank square (represented by a 2D array) following the same pattern. All formulas are given in LaTeX format. For example, the formula for a number square is denoted as: \(\text{Square} = [a_{ij}]_{n\times n}\).

inputFormat

The input consists of one integer n (\(1 \le n \le 1000\)) which denotes the dimension of the square.

outputFormat

Output the filled number square in n lines, each containing n space-separated numbers.

sample

1
1

</p>