#C2156. Spiral Grid Generator

    ID: 45441 Type: Default 1000ms 256MiB

Spiral Grid Generator

Spiral Grid Generator

You are given a positive integer NN. Your task is to generate an N×NN \times N grid filled with numbers from 11 to N2N^2 in spiral order. The spiral starts from the top-left corner and moves to the right, then downward, then to the left, and upward, repeating the sequence until the entire grid is filled. The problem requires you to read the input from stdin and output the grid to stdout. Each row of the grid should be output on a new line with values separated by a single space.

inputFormat

The input consists of a single integer NN (1N1001 \leq N \leq 100) provided via stdin. This integer represents the dimensions of the square grid.

outputFormat

Print the N×NN \times N spiral grid, where each row is printed on a separate line, and each integer in a row is separated by a space. There should be no extra spaces at the end of the lines.## sample

1
1