All problems

Assigning Every Point

easyPythonK-Means Clustering

The hand check went well, so Wexford Couriers wants the whole address file booked against the same shortlist of candidate locker sites. Each address goes to the site it would travel least far to reach, as the crow flies. The sites themselves are fixed for this run: they are the planners' shortlist and they do not move while the file is being worked through, whatever the bookings turn out to look like.

Task: Print the booked site for every address.

Input

The first line holds one integer k, the number of candidate sites. Each of the next k lines holds one site's two map coordinates, separated by a single space. The line after those holds one integer n, the number of addresses. Each of the next n lines holds one address's two coordinates.

Output

n lines, one per address, in the order the addresses arrived. Each line holds the booked site's position in the list, counting the first site as 0. An address exactly equidistant from two sites goes to whichever appears earlier in the list.

Example:

Input:
2
0 0
10 10
3
1 1
9 9
4 4

Output:
0
1
0

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…