#P10590. 磁力块

磁力块

Problem Description

On a vast and boundless plain, there are NN magnet stones scattered around.

The properties of each magnet stone can be described by a 5-tuple (x,y,m,p,r)(x,y,m,p,r), where x,yx,y are its coordinates, mm is the mass of the stone, pp is the magnetic force, and rr is the attraction radius.

If the distance between magnet stone AA and magnet stone BB is no greater than the attraction radius of AA, and the mass of BB is no greater than the magnetic force of AA, then AA can attract BB.

Xiaoqujiu brings his own magnet stone LL to the position (x0,y0)(x_0,y_0) on this plain, and we can treat the coordinates of magnet stone LL as (x0,y0)(x_0,y_0).

Xiaoqujiu holds magnet stone LL and stays at the same place. All magnet stones that can be attracted by LL will be pulled over.

At any moment, he may choose to switch to any magnet stone he has already obtained (which can also be the original magnet stone LL) at (x0,y0)(x_0,y_0) to attract more magnet stones.

Xiaoqujiu wants to know: at most how many magnet stones can he obtain?

Input Format

The first line contains five integers x0,y0,pL,rL,Nx_0,y_0,p_L,r_L,N, representing Xiaoqujiu's position, the magnetic force and attraction radius of magnet stone LL, and the number of scattered magnet stones on the plain.

The next NN lines each contain five integers x,y,m,p,rx,y,m,p,r, describing the properties of one magnet stone.

Output Format

Output one integer, representing the maximum number of scattered magnet stones that can be obtained (not including the initially carried magnet stone LL).

0 0 5 10 5
5 4 7 11 5
-7 1 4 7 8
0 2 13 5 6
2 -3 9 3 4
13 5 1 9 9
3

Hint

For 30%30\% of the testdata, 1N10001 \le N \le 1000.

For another 30%30\% of the testdata, p=rp=r.

For 100%100\% of the testdata, 1N2500001 \le N \le 250000, 109x,y109-10^9 \le x,y \le 10^9, 1m,p,r1091 \le m,p,r \le 10^9.

Translated by ChatGPT 5