- Time limit: 1.00 s
- Memory limit: 512 MB
A campground is represented as a grid where each square can contain a campsite that is either reserved or free. The distance between two squares and is the Manhattan distance .
Your task is to find the distance from each free campsite to the nearest reserved campsite.
Input
The first line has two integers and : the number of reserved and free campsites.
The next lines describe the locations of the reserved campsites. Each line has two integers and .
The next lines describe the locations of the free campsites. Each line has two integers and .
You can assume that each square contains at most one campsite.
Output
Print integers: the distances from each free campsite to the nearest reserved campsite, in the input order.
Constraints
Example
Input:
4 2 1 1 5 2 2 6 4 7 1 3 7 5
Output:
2 5
Explanation: The following figure shows the map of the campground:
The distance from the first free campsite (on the left) to the nearest reserved campsite is , and the distance from the second free campsite (on the right) to the nearest reserved campsite is .