Question
Matrix Spiral II

You are given a single integer KaTeX can only parse string typed expression. Your task is to create a square matrix of size KaTeX can only parse string typed expression and fill it with numbers from KaTeX can only parse string typed expression to KaTeX can only parse string typed expression in spiral order.

Spiral order means you start filling the matrix from the top-left corner, move left to right across the first row, then go top to bottom along the last column, then right to left across the last row, and then bottom to top along the first column.

You continue this pattern while moving toward the center of the matrix until all numbers from KaTeX can only parse string typed expression to KaTeX can only parse string typed expression are placed.

In other words, you keep filling the outer boundary of the matrix first, then move inward layer by layer in a spiral pattern.

Input
The first line contains a single integer KaTeX can only parse string typed expression — the size of the square matrix.
Output
Print an KaTeX can only parse string typed expression matrix where the numbers from KaTeX can only parse string typed expression to KaTeX can only parse string typed expression are arranged in spiral order.
Example
Input
3

Output
1 2 3
8 9 4
7 6 5

Explanation

We need to fill numbers from KaTeX can only parse string typed expression to KaTeX can only parse string typed expression because KaTeX can only parse string typed expression.

Step-by-step spiral filling:
Fill the top row → KaTeX can only parse string typed expression
Fill the right column downward → KaTeX can only parse string typed expression
Fill the bottom row from right to left → KaTeX can only parse string typed expression
Fill the left column upward → KaTeX can only parse string typed expression
Finally place the last number in the center → KaTeX can only parse string typed expression

The final matrix becomes:
1 2 3
8 9 4
7 6 5

Input
1

Output
1

Explanation
Since the matrix size is KaTeX can only parse string typed expression, we only place the number KaTeX can only parse string typed expression.

Online