Expeditions

아직 제출이 없습니다시간 제한0.15초메모리 제한16 MB

문제

Deni is working at the accounting department of the Shumen university and was given the following task: during the summer the university has sent MM students, numbered from 11 to MM, on ethnographic expeditions in different places. Due to the circumstances, all places are near a road that starts from Shumen and student with number ii is located in place that is x_ix\_i kilometers away from Shumen. All x_ix\_i are non-negative integers and we have that x_1x_2x_M1x_Mx\_1 ≤ x\_2 ≤ \dots ≤ x\_{M-1} ≤ x\_M.

Because of the intense science work during the summer 😉 the students have spent all their money and have made a request to the university for more money so that they can return to Shumen. Each student will use the road, leading to Shumen, in the direction from his place to Shumen. He can walk and use a bus from some of the places near Shumen. When he walks, student with number ii needs v_iv\_i levs for each kilometer for food and other needs. Also, there are buses in NN places which the students can rent. A bus in a place, which is y_jy\_j kilometers away from Shumen, costs c_jc\_j levs to be rented and it can transport the students that are using it to return to Shumen. If a bus is rented once, then it can be used by several students, who have gathered at this place, paying the cost c_jc\_j only once. The buses travel directly to Shumen without intermediate stops for other people to get in. The university has set the condition that every student should return to Shumen with a bus so it will be certain that every student will get off at the stop of the university and will go to the university to give the materials that have been collected during the expedition.

Write a program expedition to help Deni calculate the minimum total amount of money which is needed so that all students can return to Shumen. Furthermore – the university management wants to know what are the minimal amounts for the return of only the first student (who is located in the nearest place), only the first 22 students (with numbers 11 and 22) and so on, lastly of all the MM students.

입력

The first line of the standard input contains the positive integer NN – the number of places that have buses for rent.

The following NN lines contain two non-negative integers, separated by a space, and the jj-th of them contains:

  • y_jy\_j – the distance from Shumen to the corresponding place in which a bus can be rent;
  • c_jc\_j – the cost for renting a bus in that place.

The next line contains the positive integer MM – the number of students which are sent on ethnographic expeditions.

The last MM lines contain two non-negative integers, separated by a space, and the ii-th of them contains:

  • x_ix\_i – the distance from Shumen to the place where the corresponding student was sent on ethnographic expedition;
  • v_iv\_i – the amount of money that student needs for walking one kilometer.

출력

On the only line of the standard output print MM numbers, separated by spaces – the minimum amounts of money which are needed for the return of only the first student (who is located in the nearest place), only the first 22 students (with numbers 11 and 22) and so on, lastly of all the MM students. It is guaranteed that all amounts are smaller than 2×10182\times 10^{18}.

제한

  • 1N,M1051 ≤ N, M ≤ 10^5
  • 0x_i,y_j2300 ≤ x\_i, y\_j ≤ 2^{30}; y_0x_0y\_0 ≤ x\_0 and x_ix_i+1x\_i ≤ x\_{i+1} for all 1i<N1 ≤ i < N; y_jy_j+1y\_j ≤ y\_{j+1} for all 1j<M1 ≤ j < M
  • 1v_i2301 ≤ v\_i ≤ 2^{30}
  • 1c_j2401 ≤ c\_j ≤ 2^{40}