Jogging in Manhattan
Time limit2sMemory limit1024 MB
Given navigator readings every t minutes, each within Manhattan distance d of Misha's true position, find all lattice points he can occupy at the final time.
- Level
Medium6 of 10
- Topics
- Math, Geometry, Implementation, Simulation
- Solved
- No attempts yet
Problem
The roads of New Manhattan are laid out as follows. Avenues run from south to north every one hundred meters, and streets run from west to east every one hundred meters. Avenues and streets are numbered with integers. Smaller numbers correspond to western avenues and southern streets. Thus we can set up a rectangular coordinate system so that the point lies at the intersection of the -th avenue and the -th street. It is easy to see that to get from to in New Manhattan, one must walk blocks. This quantity is called the Manhattan distance between the points and .
Misha lives in New Manhattan and goes for a run through the city every morning. He starts from his home at and runs along a random route. Each minute, Misha either stays at the same intersection as the minute before or moves one block in any direction. To avoid getting lost, Misha takes a navigator with him, which every minutes tells Misha which point he is at. Unfortunately, the navigator does not show Misha's exact position; it may show any point whose Manhattan distance from Misha does not exceed .
After minutes from the start of the run, having received the -th message from the navigator, Misha decided it was time to run home. To do so, he wants to know which points he can be at. Help Misha do this.
Input
The first line of the input file contains the numbers , , and (, , ).
The next lines describe the data received from the navigator. Line contains the numbers and , the data received from the navigator minutes after the start of the run.
Output
In the first line of the output file, print the number , the number of points where Misha can be. Then print pairs of numbers, the coordinates of the points. The points may be printed in any order.
The navigator is guaranteed to be working, and there is guaranteed to be at least one point where Misha can be.