#K44192. Spiral Matrix Generator

    ID: 27477 Type: Default 1000ms 256MiB

Spiral Matrix Generator

Spiral Matrix Generator

You are given a positive integer n and your task is to generate an n × n spiral matrix. The matrix is filled with consecutive integers from 1 to n^2 in spiral order. The spiral starts from the top-left corner and moves to the right initially.

Constraints:

  • \(1 \le n \le 500\)

If the input value of n does not fall within the allowed range, output the exact error message: "n must be between 1 and 500 inclusive."

Example:

Input: 3
Output:
1 2 3
8 9 4
7 6 5

inputFormat

The input consists of a single integer n provided via standard input.

outputFormat

If n is in the range [1, 500], output the spiral matrix where each row is printed on a new line and the numbers in each row are separated by a single space. If n is out of range, output the error message: "n must be between 1 and 500 inclusive."

## sample
3
1 2 3

8 9 4 7 6 5

</p>