10390 - How to move?   

Description

Suppose we have an NxN map. N=2k+1 The map consists of numbers 1~99.
For example,M=
75    69    81    43    49
73      3    68    37    44
38    27    31    72    63
64      4    94    78    70
16      9      3    18    74


we walk t step
Now, start walking from the center of map M(k+1,k+1)(in the example is 31)
the next position is determined by the number which we stand
Use number mod 4 to choice direction
Directions (Right:mod=0, Down:mod=1, Left:mod=2, Up:mod=3)
if next position is not on the map,next step we will not move

Input

t(number of move) n(size of map)
Map

note that there is a blank between neighbor elements in each row of Map.

Output

print the number we visit by sequence(t+1 numbers), where there is a blank space between neighbor numbers and no new line at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss