Number of pairs
Very hard
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
You are given n points on the line y = 0. Your task is to answer queries regarding the number of pairs of points that have a distance equal to k.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5
). The second line contains n integers, representing the x-coordinates of the points, where each coordinate is between 0 and 10^5
. All points have distinct coordinates. The third line contains an integer q, the number of queries. Each of the following q lines contains a single integer k[i]
(0 ≤ k[i]
≤ 10^9
).
Output
For each query, output the number of pairs of points that have a distance equal to the given k, with each result on a new line.
Examples
Input #1
Answer #1
Submissions 267
Acceptance rate 5%