On a square grid, we start in (0,0) and we draw a spiral path. Then, on this spiral path, we mark one square with the first color, then two squares with the second color, three squares with the third color, etc. To limit the number of colors, we pick a number (these values give the prettiest results) and use only colors (we go back to color 1 instead of ). The results are shown on the pictures.
We would like to quickly calculate which color will be used on a square grid with given coordinates.
Each line contains three integers , where and .
Input ends with a line containing 0 0 0.
For each output the color of point , as a number from to . Positive coordinates go rightwards, and positive coordinates go upwards.
Input
2 0 0 2 -1 0 2 -1 -1 2 0 -1 2 1 -1 2 1 0 2 1 1 3 0 0 3 -1 0 3 -1 -1 3 0 -1 3 1 -1 3 1 0 3 1 1 0 0 0
Output
1 2 2 1 1 1 2 1 2 2 3 3 3 1