Page not loading? Try clicking here.
Placeholder

#1707

Snail square 1s 64MB

Problems

Given the size of a square, write a program that fills the square in a clockwise spiral pattern as shown below.

Conditions

  1. Start filling numbers from the top-left corner.

  2. Move to the right, and when reaching the edge, continue filling downward, then left, then upward, repeating this clockwise pattern until the entire square is filled.


Input

A single integer ๐‘› is given, representing the size of the square.

๐‘› is an integer between 1 and 100 inclusive.


Output

Print the square after filling it with numbers in the clockwise spiral pattern.

Separate numbers with a space.


Example #1

2
1 2

4 3

Example #2

5
1 2 3 4 5

16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9


Source

JUNGOL

You must sign in to write code.