This page is still under construction.

Parts of this page are still being built. What you see may change.

Jogging in Manhattan

Time limit2sMemory limit1024 MB

Summary
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 (x,y)(x, y) lies at the intersection of the xx-th avenue and the yy-th street. It is easy to see that to get from (x1,y1)(x_1, y_1) to (x2,y2)(x_2, y_2) in New Manhattan, one must walk ∣x2−x1∣+∣y2−y1∣|x_2 - x_1| + |y_2 - y_1| blocks. This quantity is called the Manhattan distance between the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).

Misha lives in New Manhattan and goes for a run through the city every morning. He starts from his home at (0,0)(0, 0) 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 tt 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 dd.

After t⋅nt\cdot n minutes from the start of the run, having received the nn-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 tt, dd, and nn (1≤t≤1001\le t\le 100, 1≤d≤1001\le d\le 100, 1≤n≤1001\le n\le 100).

The next nn lines describe the data received from the navigator. Line ii contains the numbers xix_i and yiy_i, the data received from the navigator t⋅it\cdot i minutes after the start of the run.

Output

In the first line of the output file, print the number mm, the number of points where Misha can be. Then print mm 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.

Examples1

  1. Example 1

    Input
    2 1 5
    0 1
    -2 1
    -2 3
    0 3
    2 5
    
    Expected output
    2
    1 5
    2 4