Lawn
InterviewTime limit2sMemory limit512 MB
Count the integer lattice points inside an axis-aligned rectangle that also lie within distance r of a given point.
- Level
Medium6 of 10
- Topics
- Math, Geometry, Binary search, Implementation
- Solved
- No attempts yet
Problem
Farmer Ivan has tended his lawn since he was young. The lawn can be viewed as a plane in which one tuft of grass grows at every point with integer coordinates.
One Sunday Ivan used a lawn mower and cut a rectangular patch of the lawn. The sides of this patch are parallel to the coordinate axes, and two opposite vertices are at and . Note that the tufts of grass lying on the boundary of this rectangle were also cut.
Pleased with the result, Ivan bought and installed a sprinkler on the lawn. It was placed at the point with coordinates and had a jet reach of . So the sprinkler began watering every tuft whose distance to did not exceed . Everything was fine, but Ivan wondered: how many tufts of grass were both cut and watered that Sunday?
Write a program that answers Ivan's question.
Input
The first line of the input file contains four integers (; ).
The second line of the input file contains three integers (; ).
Output
Print a single integer: the number of tufts of grass that were both cut and watered.
Notes
