Intertwined
시간 제한1초메모리 제한1024 MB
길이 d인 밧줄이 원점을 중심으로 반시계 방향으로 회전하다가 닿는 기둥을 축으로 삼아 다시 회전하는 과정을 반복할 때, 마지막으로 회전 축이 된 기둥의 번호를 출력하거나 없으면 -1을 출력한다.
문제
NCPC (Nordic Cargo Plane Control) are testing a new engine for their cargo planes. To this end they have bound a strong and sturdy infinitely thin rope to the centre of their testing platform, and to the engine. We will place a coordinate system onto this testing platform such that the rope is bound at the origin and lays along the positive -axis to . On this testing platform there are also a number of infinitely thin pillars that can stop the rope, but ignore the engine. As the engine is started it starts rotating the rope counter-clockwise around the origin until it hits a pillar, at which point it is caught and starts rotating around that pillar counter-clockwise instead. The engine is then rotating at a smaller radius as some of the rope is caught between the origin and this pillar. This keeps going until the rope is too short to reach any other pillars.
Running these tests, buying all this infinitely thin rope and setting up these infinitely thin pillars, is expensive. Besides, the workers keep getting these nasty paper-like cuts from all these infinitely thin objects. It would be much more economical to just simulate the behaviour.
입력
The first line contains an integer , the number of pillars, and an integer , the length of the rope (, ).
The following lines each contain two integers , , the coordinates of the th pillar () for . None of these pillars will lie on the rope.
출력
Print one line with an integer , meaning that the rope will end up spinning around the th pillar in the input. Note that this index is -indexed. If the rope doesn't collide with any pillars . It is guaranteed that changing the input by at most will not change .