This page is still under construction.

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

Vicinity

Interview

Time limit1sMemory limit128 MB

Summary
For each query, count how many of the n points lie within distance d_v of the chosen base point, excluding the base point itself.
Level

Easy2 of 10

Topics
Brute force, Geometry
Solved
No attempts yet

Problem

You are given several points in the plane. Pick one of them as the base point and count how many points lie close to it.

Let the set of points be P={p1,p2,…,pn}P = \{p_1, p_2, \dots, p_n\}, where pip_i has coordinates (xi,yi)(x_i, y_i). Write d(pi,pj)d(p_i, p_j) for the Euclidean distance between two points. Point pjp_j is in the vicinity of point pip_i when d(pi,pj)≤dvd(p_i, p_j) \le d_v, and dvd_v is called the vicinity distance.

Given the set PP, a base point pip_i and a vicinity distance dvd_v, write a program that computes how many points are in the vicinity of pip_i. The base point pip_i itself is not counted.

Input

The first line contains the number of points nn (2≤n≤10002 \le n \le 1000). Each of the next nn lines contains the integer coordinates xix_i and yiy_i of one point (−106≤xi,yi≤106-10^6 \le x_i, y_i \le 10^6).

The next line contains the number of queries tt (1≤t≤501 \le t \le 50). Each of the following tt lines contains two positive integers ii and dvd_v (1≤i≤n1 \le i \le n, 1≤dv≤1001 \le d_v \le 100), meaning the base point pip_i and its vicinity distance dvd_v.

Output

For each query, print on its own line how many points are in the vicinity of the base point.

Examples1

  1. Example 1

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