ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2218. Prorun

Time limit: 3.0 second
Memory limit: 256 MB
Recently, Vadim invented a new sport called “Prorun”: a combination of programming and running. To simplify the rules, the goal of the prorun is to run a specific distance to a computer and solve a problem on it. It is known that each of the N computers is located on a Cartesian plane, with each one positioned at its own point.
The authors of today’s contest decided to participate in the prorun. It is known that there are Q participants, each standing somewhere on the plane (not necessarily at different points), and each has a distance dj that the j-th participant needs to run to reach one of the computers. Moreover, it is decided that running can only be parallel to the coordinate axes, and if it is possible to reach a computer with a shorter distance than required by the participant, then that computer cannot be reached.
The inventor of the prorun and the author of today’s contest, Vadim, knows in advance where the computers will be located, where all the participants will stand, and the required distance for each. To have a slight advantage over his competitors, Vadim wanted to calculate how many different computers are suitable for each participant in the prorun. Help him find these counts.

Input

The first line contains an integer N — the number of computers (1 ≤ N ≤ 105).
The following N lines contain two integers cxi and cyi — the coordinates of the i-th computer (|cxi|, |cyi| ≤ 109).
It is guaranteed that no two computers are located at the same point.
The next line contains an integer Q — the number of participants in the prorun (1 ≤ Q ≤ 105).
The following Q lines contain three integers qxj, qyj, and dj — the coordinates of the j-th participant and the required distance for them to run (|qxj|, |qyj| ≤ 109, 0 ≤ dj ≤ 4 · 109).

Output

Output Q integers mj — the number of computers that the j-th participant can reach.

Sample

inputoutput
5
0 0
1 1
2 0
1 -1
1 0
4
1 0 1
2 2 2
5 1 5
0 1 4
4
2
1
0
Problem Author: Vadim Barinov
Problem Source: ICPC Ural Regional Contest Qualifier 2025