Frog
Time limit1sMemory limit128 MB
Given axis-aligned non-touching squares in the first quadrant and a jump reach d, find the largest x+y over squares reachable from the square at the origin.
Problem
A frog lives in a pond dotted with lily pads, and it loves to hop from one lily pad to another.
The pond is the region of the coordinate plane with and . Each lily pad floating in the pond is a square of side length whose sides are parallel to the coordinate axes. All lily pads have the same size, no two of them overlap, and no two of them touch along their borders.

Figure 1
There is always a lily pad that contains the point , and the frog starts on this lily pad.
In a single jump the frog can move a distance of at most , but only in one of the four directions: east, west, south, or north. Therefore, when the frog jumps from a lily pad , the region it can reach is the shaded area in Figures 2 and 3. To jump from lily pad to another lily pad , some part of must lie inside this region (Figure 2). As in Figure 3, it is enough for the border of to merely touch this region.

Figure 2

Figure 3
By walking freely on a lily pad and by jumping from lily pad to lily pad, the frog can reach several lily pads. Among all points on the lily pads the frog can reach, find the distance to the point that is farthest from . Here the distance of a point from is defined as .
Input
The first line contains the number of lily pads and the side length of a lily pad, separated by a space (, ).
Each of the next lines contains the coordinates and of the bottom-left corner of one lily pad, separated by a space ().
The last line contains the maximum distance the frog can travel in a single jump ().
Output
Print, on a single line, the distance to the farthest point the frog can reach from .