#C3905. Spiral Matrix Generation

    ID: 47384 Type: Default 1000ms 256MiB

Spiral Matrix Generation

Spiral Matrix Generation

Given a non-negative integer n, generate an n × n spiral matrix. The matrix should be filled with the numbers from 1 to n^2 in a clockwise spiral order. That is, the first row is filled from left to right, then the last column from top to bottom, then the last row from right to left, and finally the first column from bottom to top, continuing inward.

In mathematical notation, if n is the input, you are to construct a matrix A of size $n \times n$, where the elements are filled from 1 to $n^2$ in spiral order.

inputFormat

The input consists of a single integer n read from standard input. Here n is a non-negative integer. If n is zero, output nothing.

Input Format:

n

outputFormat

Output the generated spiral matrix to standard output. Each row of the matrix should be printed on a new line, with numbers separated by a single space.

Output Format:

a11 a12 ... a1n
...
an1 an2 ... ann
## sample
1
1