11857 - Another Spiral   

Description

In this problem, you are asked to output a sequence of integer number (i.e. 0, 1, 2, 3 ......) in the "spiral form".

A square is an area with NxN grids. You put the first number (i.e. 0) in the position according to the input. Then, you put the next number  to the right (or left) of the previous one, and you will reach the right (or left) border of the square. Any time you can't find an empty place on current direction, you turn "right" (or "left") and place the next number until your direction is opposite to origin direction which you reach this grid.

 

Sample IO shows four testcases, your input has only four integer and output N*N number.

Input

There are four integer numbers for the input. The first number N (1<= N <= 20) denotes the size of the edges of the square. The second number decides the direction of this case (0 means clockwise, and 1 means anticlockwise). The third and forth number mean the initial position in which row and column.

Output

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

If the gird is not reached, the content should be 0. (note: the content of initial position is also 0)

note: print a space before each number, and print '\n' in the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss