#K4921. Spiral Matrix Generator

    ID: 28592 Type: Default 1000ms 256MiB

Spiral Matrix Generator

Spiral Matrix Generator

Given a non-negative integer \(m\), your task is to generate an \(m \times m\) spiral matrix. The matrix should be filled with consecutive integers from 1 to \(m^2\) in a clockwise spiral order, starting from the top-left corner.

For example, when \(m = 3\), the generated spiral matrix is:

\[ \begin{bmatrix} 1 & 2 & 3 \\ 8 & 9 & 4 \\ 7 & 6 & 5 \end{bmatrix} \]

If \(m = 0\), the matrix is empty.

inputFormat

The input is read from stdin and consists of a non-negative integer \(m\), which represents the size of the matrix.

outputFormat

Output the \(m\times m\) spiral matrix to stdout. Each row should be printed on a new line with numbers separated by a single space. If the matrix is empty (i.e. when \(m = 0\)), output nothing.

## sample
3
1 2 3

8 9 4 7 6 5

</p>