A Spiral Walk

No attempts yetTime limit1sMemory limit128 MB

Problem

The cows love to walk in their square pasture, which has sides of length $N$ ($1 \le N \le 750$) and is partitioned into $N \times N$ unit squares.

Bessie has planned the longest possible walk that starts at the upper-left square and ends at the center of the pasture (or near the center when $N$ is even), passing through every square exactly once after starting.

She has chosen a clockwise spiral route (illustrated below). Write a program that prints a map showing the order in which she visits each square.

For example, for pastures of size $N=3$ and $N=4$, the visiting orders are:

1  2  3        1  2  3  4
8  9  4       12 13 14  5
7  6  5       11 16 15  6
             10  9  8  7

Input

The first line contains a single integer $N$.

Output

Print $N$ lines, each containing $N$ space-separated integers. Each integer is the order in which the corresponding square is visited.