Under construction

Still being built. Things may change

Billiards

Time limit8sMemory limit1024 MB

Summary
Given a billiard table with balls and a coin, find every ball that, struck at 45 degrees, reaches the coin after cushion bounces before hitting another ball or a corner hole.
Level

Medium7 of 10

Topics
Geometry, Math, Hash map
Solved
No attempts yet

Problem

You are challenging a prize game that resembles billiards. The game uses a billiard table, several balls of the same size, and a prize coin. The top of the table has a flat rectangular cloth-covered area bounded by elastic bumpers called cushions. The balls move on this area. The cushions keep the centers of the balls inside a rectangular region of width aa and length bb, called the movable area.

Let the coordinates of the four corners of the movable area be (0,0)(0, 0), (a,0)(a, 0), (a,b)(a, b), and (0,b)(0, b). At the start of a game, all the balls and the coin are placed so that their centers are at distinct inner lattice points of the movable area, that is, points not on its boundary. The balls and the coin are small, so they do not touch each other unless a ball moves toward the center of another ball or the coin.

You choose one ball and strike it with a cue in the direction 45 degrees to the edges of the movable area. The direction is one where both the xx and yy coordinates increase. The struck ball moves straight until it reaches a boundary of the movable area, hits another ball, or drops into one of the holes at the four corners. When the ball reaches a boundary, it bounces off the cushion with a reflection angle equal to its incident angle and continues straight. When it hits another ball or drops into a corner hole, the game is over. If it hits the coin before hitting another ball or dropping into a hole, you win the coin.

Which ball should you strike to win the coin? You want to know all the balls that bring you the coin.

Figure F-1: The first and second datasets of the sample input.

For the first dataset, when ball No. 2 is struck, it goes directly toward the coin. Ball No. 4 hits the coin after bouncing off the right-side cushion. Ball No. 1 hits ball No. 2, and ball No. 3 drops into the upper right hole, so striking either of them does not win the coin.

For the second dataset, when only ball No. 1 is struck, it bounces off the cushions 5 times and passes through its original position. After bouncing twice more, it reaches the coin.

Input

The input consists of multiple datasets, each in the following format.

aa bb xx yy nn

x1x_1 y1y_1

⋮\vdots

xnx_n yny_n

The first line has five integers. aa and bb are the width and length of the movable area, with 2≤a≤1062 \le a \le 10^6 and 2≤b≤1062 \le b \le 10^6. xx and yy are the coordinates (x,y)(x, y) of the coin, with 1≤x<a1 \le x < a and 1≤y<b1 \le y < b. nn is the number of balls, with 1≤n≤1051 \le n \le 10^5.

The balls are numbered from 1 to nn. Line ii of the following nn lines gives the center of ball ii as two integers xix_i and yiy_i, with 1≤xi<a1 \le x_i < a and 1≤yi<b1 \le y_i < b. The positions of the coin and all the balls are mutually different.

The end of the input is a line with five zeros. The number of datasets does not exceed 50. The sum of nn over all datasets does not exceed 5×1055 \times 10^5.

Output

For each dataset, output on one line all the ball numbers you should strike to win the coin, separated by a single space, in ascending order. If no such ball exists, output "No" on one line.

Examples1

  1. Example 1

    Input
    6 6 4 4 4
    2 2
    3 3
    5 5
    5 1
    4 5 2 2 1
    3 3
    4 5 1 4 3
    1 2
    3 4
    3 2
    0 0 0 0 0
    
    Expected output
    2 4
    1
    No