Hungry Games

0

0 votes
Problem

Saurabh and Pranav play the popular game of Hungry Birds on windows and android phones respectively.

The game goal is to destroy birds in the Hungry Birds Game. A certain number of points is given for destroying each bird depending on the bird type and the current factor value.

There are n types of Hungry Birds. The number of birds of type ai and bird cost ci is known for each bird type. A player gets ci.f points for destroying one bird of type i, where f is the current factor. The factor value can be an integer number from 1 to t + 1, inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i + 1 after destruction of pi (1 <= i <= t) birds, so the (pi + 1)-th bird to be destroyed is considered with factor equal to i+1.

Your task is to determine the maximum number of points Saurabh and Pranav can get after they destroy all birds. Take into account that they are so tough that they can destroy birds in any order chosen by them individually on their respective phones.

Input :


The first line contains the only integer number n (1 <= n <= 100) — the number of bird types.

Each of the following n lines contains two integer numbers ai and ci (1 <= ai <= 10^9, 0 <= ci <= 1000), separated with space — the number of birds of the i-th type and the cost of one i-type bird, correspondingly.

The next line contains the only integer number t (1 <= t <= 100) — the number that describe the factor's changes.

The next line contains t integer numbers pi (1 <= p1 < p2 < ... < pt <= 10^12), separated with spaces.

Output :


Print the only number — the maximum number of points they can get.

Sample Input
2
3 8
5 10
1
20
Sample Output
74
Time Limit: 2
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?