All problems

Finding the Single Nearest Neighbor

mediumPythonK-Nearest Neighbors

Marlow Utilities sends an engineer out the moment a fault is reported. A fault arrives as a position on the map. The company also keeps a list of depots, each with its own map position and a short code. The dispatch rule is the simplest one there is: the crew comes from whichever depot lies nearest to the fault as the crow flies. No two depots are ever exactly the same distance from a given fault, so there is always a single winner and never anything to argue about.

Task: Print the code of the depot nearest to the reported fault.

Input

The first line holds the fault's two map coordinates, separated by a space. The second line holds n, the number of depots. Each of the next n lines holds a depot's two coordinates followed by its code, separated by single spaces. A code contains no spaces. Coordinates may be negative or fractional, and the depots' distances from the fault are guaranteed to be all different.

Output

One line holding the winning depot's code, copied exactly as it appeared in the input.

Example:

Input:
0 0
3
2 0 A
0 5 B
1 0 C

Output:
C

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…