11167 - Spiral Text   

Description

In this problem, you are ask to rearrange a given text in a square and output it in hte "spiral form".

A square is an area with NxN grids. For a given text with length NxN, you put the first character in the upper-left grid. Then, you put the next N-1 characters to the right of the previous one, and you will reach the right border of the square. Any time you can't find an empty place on current direction, you turn "right" and place the next character untile you finish placing all characters and reach the center of the square.

The case below shows the result of a text "0123456789ABCDEF" in a 4x4 square:

0123
BCD4
AFE5
9876

Input

There are 2 lines for the input. The first shows the integer N (1<= N <= 8) denotes the size of the edges of the square. The following line is a text with exactly NxN characters. There might be Alphabets, numbers and spaces in the text.

If you use getchar() to fetch characters in the text, make sure you handle the "new line" ('\n') character in the first line properly.

Output

Print the texts in the square. There should be N lines in the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss