400473: GYM100187 M Heaviside Function

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. Heaviside Functiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

The 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.

Output

Output m lines. i-th line should contain the value of f(xi).

ExamplesInput
6
1 3
-1 2
1 9
-1 2
1 7
-1 2
8
0 12 2 8 4 -3 7 9
Output
0
3
0
2
1
3
2
3

加入题单

算法标签: