Олимпиадный тренинг

Задача 21812. conquest


Задача

Темы:
Lord Petyr is gathering an army to march on a neighboring kingdom. He wants to join his army
all the warriors from each of the n cities of his kingdom entered. Petyr figured out what people are looking for in the i-th city
the job of ai warriors he can recruit into his army.
Initially, there is not a single warrior in the Lord's army. For a warrior to join the army, Petyr can pay
this warrior. To recruit one warrior from the i-th city, you need to pay him ci gold coins.
At the same time, warriors from big cities appreciate their work more, so if for the i-th and j-th city
done ai < aj , then ci ≤ cj .
However, there is another way to get warriors to join the army. If in
at some point it turns out that in the army of Lord Petyr there are already strictly more warriors than there are left
in a certain city, then all the warriors of this city join the army of the Lord for free.
Help Lord Petyr figure out what is the minimum amount of gold coins he owes
pay warriors so that all warriors from all cities are in his army.

Input data format
The first line of the input file contains an integer n (1 ≤ n ≤ 1000) — number of cities,
in which Lord Petyr intends to recruit warriors. In the next n lines of the input file
find two integers each ai and ci (1 ≤ ai ≤ 100, 1 ≤ ci< /sub> ≤ 10,000) — number of warriors in
i-th city and the number of coins to be paid to one warrior in this city so that he
joined the army. For all pairs i and j, the condition is fulfilled that if ai < aj , then ci ≤ cj .

Output Format
In the output file print a single integer — the minimum number of coins that the Lord
Petyr will have to pay to have all the warriors join his army.

Input:
3
1 1
2 2
4 3

Output: 5


In the above example, the Lord needs to act as follows. He pays first
2 coins to the warrior from the second city, and 3 coins to the warrior from the third city to join
to his army.
Now there are 2 warriors in the Lord's army, and 1, 1 and 3 warriors left in the cities, respectively. Warriors from
of the first and second cities join the army of Lord Petyr for free, in his army becomes
4 warriors, after which the remaining 3 warriors from the third city join his army for free.