k_35P likes to play with magnets. He has placed
Upon reaching the floor, a metal piece will also immediately move to the nearest (as per Manhattan distance) floor tile which has a magnet on it — the magnets do not move. If a metal piece is equidistant to two or more magnets that are tied for closest distance, it will not move, even if the magnets are at the same coordinates.
Before k_35P drops any metal, however, he's allowed you to place exactly one additional magnet at any integer coordinate on the floor (including directly under a tile where a piece of metal will land). You want to place this magnet such that it will collect as many pieces of metal as possible. Unable to solve this problem by hand, you've decided to write a program to determine the maximum number of metal pieces that your magnet can collect, if placed optimally.
Note
The Manhattan distance
Constraints
For 40% of the points,
For an additional 10% of the points,
For all cases,
Input Specification
The first line will contain
In the next
The next line will contain a single integer
For the next
Output Specification
A single integer, the maximum number of metal pieces you can collect by placing a single magnet.
Sample Input 1
1
0 0
2
0 1
1 0
Sample Output 1
1
Explanation for Sample Output 1
A magnet can be placed either directly where the first piece of metal will fall, or the second. Placing it anywhere else will result in it collecting no metal, as both pieces of metal are
Sample Input 2
3
0 0
10 0
5 5
3
3 0
5 2
7 0
Sample Output 2
3
Explanation for Sample Output 2
Place a magnet at
Sample Input 3
1
9 21
3
0 14
18 33
21 19
Sample Output 3
2
Comments
Sorry, the magnet must be placed at integer coordinates.
The statement has been updated to use
integer
instead ofintegral
, as it apparently confused some people.Can you place the new magnet on top of another magnet?
Yes.
Sorry, should have specified: and a piece of metal that is closest to the two magnets on top of each other would not move?
This question can be answered unambiguously from the problem statement. Please reread it.
Do you mean a piece of metal which has the two magnets tied for the shortest distance?