Page not loading? Try clicking here.
Placeholder

#1337

Snail triangle 1s 64MB

Problems

Given the height 𝑁 of a triangle, write a program that fills the triangle in a snail (spiral) pattern with numbers from 0, as shown below.

Conditions

  • Start from the top-left and move diagonally down to the right, filling numbers from 0 up to 𝑁.

  • Then move to the left, and then upward, repeating this clockwise spiral pattern.

  • After 9, continue numbering from 0 again.


Input

A single integer 𝑁 is given, representing the length of one side of the triangle.

𝑁 is a positive integer not exceeding 100.


Output

Print the snail-shaped triangle with height N according to the given pattern.

Separate numbers with a single space.


Example #1

3
0
5 1
4 3 2

Example #2

4
0
8 1
7 9 2
6 5 4 3

Example #3

6
0

4 1
3 5 2
2 0 6 3
1 9 8 7 4
0 9 8 7 6 5


Source

JUNGOL

You must sign in to write code.