Donut-shaped Enclosure
Time limit3sMemory limit1024 MB
Place a Chebyshev-distance donut with inner radius L and outer radius R at a lattice center to maximize the total weight of covered points.
- Level
Hard8 of 10
- Topics
- Geometry, Prefix sum, Sorting, Math
- Solved
- No attempts yet
Problem
The distance system usually used in the two-dimensional plane is Euclidean distance. In Euclidean distance, the distance between two points and is written as .
This problem deals with Chebyshev distance instead of Euclidean distance. In Chebyshev distance, the distance between and is written as .
For a given distance system, a circle of radius is the set of points whose distance to a specific point is . The shape of a circle depends on which distance system is used. As (Figure 1) shows, under Euclidean distance it is the circular shape we usually know, and under Chebyshev distance a square with side length becomes the circle.

Figure 1 : Circles under Euclidean distance and Chebyshev distance
Also, for a given distance system, a donut with inner radius and outer radius is the set of points whose distance to a specific point is at least and at most .
In (Figure 2), the left side is a donut under Euclidean distance and the right side is a donut under Chebyshev distance. The gray region is the region included in the donut.

Figure 2 : Donuts under Euclidean distance and Chebyshev distance
Bumsoo is playing with points , , , and a donut under Chebyshev distance whose inner radius is and outer radius is . is located at , and Bumsoo can freely change the position of the donut's center as long as he keeps the center's coordinates on a lattice point. If lies in the donut region, Bumsoo is forced to gain points, and if it does not lie in the donut region, he gains no points. Write a program that finds the maximum score Bumsoo can gain.
Input
The first line of the input gives three integers , , (, ), separated by a single space.
The -th of the following lines gives , , (, ), separated by a single space. Multiple points may be at the same position.
Output
On the first line, print the maximum score Bumsoo can gain.
Hint
For the first sample, it is enough to put the donut's center at or .
For the second sample, the donut has become too large, so the best choice is to include one of the s while avoiding the s.