Simulate a scooter rider who turns right at every intersection, and report her road after N turns or when she exits the city.
Medium7GeometrySimulationGraphNo attempts yetTime limit2sMemory limit512 MBLast week your little sister got a scooter for her birthday. Since then she goes out for a ride several times a day without telling anyone. She leaves the house and rides along the pavement beside the road. She knows that she must not cross a road, and she is not yet skilful enough to turn her scooter around on the pavement. So every time she reaches an intersection, she turns right.
You are tired of being sent after her. You know how she rides, so you decide to write a program that tells you which road she is on.
The city has R roads. Each road has a name and is an infinite line in the plane. No point lies on three or more roads, so exactly two roads meet at every intersection.
Your parents' house (X,Y) lies on a road that is not parallel to the y-axis, on the south side of that road. Your sister therefore sets off east, in the direction of increasing x. She repeats the following rules.
Turning right means her direction of travel bends clockwise. Of the two directions of the other road at the intersection, her new direction is the one reached by rotating her old direction clockwise by less than 180 degrees.
Find the name of the road your sister is riding on after N right turns. If she rode out of the city before completing N turns, find the name of the road she was riding on when she left.
The first line contains the number of roads R, the number of right turns N, and the coordinates X and Y of your parents' house. (1≤R≤100, 0≤N≤1010, ∣X∣≤107, ∣Y∣≤107)
Each of the next R lines describes one road. A line contains a name S of at most 20 characters that has no spaces and uses only letters and digits, followed by four integers X1, Y1, X2, Y2. Road S is the infinite line through the points (X1,Y1) and (X2,Y2). (∣X1∣,∣Y1∣,∣X2∣,∣Y2∣≤107, (X1,Y1)=(X2,Y2))
No point lies on three or more roads. Your parents' house (X,Y) lies on exactly one road, that road is not parallel to the y-axis, and the house is not at an intersection. Both coordinates of every intersection have absolute value at most 107, and two different intersections on the same road are at least 10−4 apart.
Print the name of the road your sister is riding on, on one line.

The picture shows the three roads of the first example. Your sister starts on Homedrive heading east and turns right onto Narrowlane, Broadway, Homedrive, Narrowlane in that order, so after four turns she is on Narrowlane.