Under construction

Still being built. Things may change

Crazy Transport Taxes

Interview

Time limit2sMemory limit1024 MB

Summary
Given a step-function rate table and a list of car powers, print each car's tax, which is the matching band's rate times the power.
Level

Easy3 of 10

Topics
Binary search, Array
Solved
No attempts yet

Problem

Arthur Fleck was once an ordinary person with ordinary needs. One of them was buying a car.

As is well known, owning a car means paying a transport tax, and Gotham is no exception. To find the transport tax on a car, you need its engine power in horsepower. Then look up the tax rate for that power in the rate table, and multiply the rate by the power.

An example rate table:

Power (hp)Rate
024
10035
15050
20075
250150

The rate in row ii applies to power values strictly greater than the power in that row and less than or equal to the power in the next row (if there is one). If the power is strictly greater than the maximum power in the table, the maximum rate applies.

While choosing a car, Arthur looked at many options and wants the transport tax for each one. Help him.

Input

The first line contains an integer nn, the number of rows in the rate table (1≤n≤100 0001 \le n \le 100\,000).

Each of the next nn lines contains a pair of integers bib_i, tit_i: the power and the rate for row ii (0≤bi,ti≤1090 \le b_i, t_i \le 10^9). It is guaranteed that b1=0b_1 = 0, and for every ii, bi<bi+1b_i < b_{i+1} and ti≤ti+1t_i \le t_{i+1}.

The next line contains an integer mm, the number of cars Arthur asks about (1≤m≤100 0001 \le m \le 100\,000).

Each of the next mm lines contains an integer qjq_j, the power of the jj-th car (1≤qj≤1091 \le q_j \le 10^9).

Output

For each car, print its transport tax on a separate line.

Examples1

  1. Example 1

    Input
    5
    0 24
    100 35
    150 50
    200 75
    250 150
    5
    107
    143
    152
    170
    150
    
    Expected output
    3745
    5005
    7600
    8500
    5250