400473: GYM100187 M Heaviside Function
Description
Heaviside function is defined as the piecewise constant function whose value is zero for negative argument and one for non-negative argument:
You are given the function f(x) = θ(s1x - a1) + θ(s2x - a2) + ... + θ(snx - an), where si = ± 1. Calculate its values for argument values x1, x2, ..., xm.
InputThe first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the summands in the function.
Each of the next n lines contains two integers separated by space — si and ai (si = ± 1, - 109 ≤ ai ≤ 109) — parameters of the i-th summand.
The next line contains a single integer m (1 ≤ m ≤ 200000) — the number of the argument values you should calculate the value of the function for.
The last line contains m integers x1, ..., xm ( - 109 ≤ xi ≤ 109) separated by spaces — the argument values themselves.
OutputOutput m lines. i-th line should contain the value of f(xi).
ExamplesInput6Output
1 3
-1 2
1 9
-1 2
1 7
-1 2
8
0 12 2 8 4 -3 7 9
0
3
0
2
1
3
2
3