Spiral Pattern X91450


Statement
 

pdf   zip

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 k{2,3}k \in \{2,3\} (these values give the prettiest results) and use only kk colors (we go back to color 1 instead of k+1k+1). 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.

Input

Each line contains three integers k,x,yk,x,y, where k{2,3}k \in \{2,3\} and |x|,|y|1000000000|x|, |y| \leq 1000000000.

Input ends with a line containing 0 0 0.

Output

For each k,x,yk,x,y output the color of point (x,y)(x,y), as a number from 11 to kk. Positive xx coordinates go rightwards, and positive yy coordinates go upwards.

Public test cases
  • 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
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++