Potatoes and fertilizers
문제
Farmer Gumbauskas is growing potatoes. He planted potatoes in one long furrow and placed bags with fertilisers next to the furrow.
Assume that the furrow consists of segments of the same length. The segments are numbered from to from left to right. In segment there are fertilisers and were planted potatoes. One fertiliser unit is required to fertilise one planted potato. There is enough fertiliser for all the potatoes, i.e. a_1 + \cdots + a_N ≥ b_1 + \cdots + b_N.
However, it costs to transfer fertiliser from one segment to another. To transfer one unit of fertiliser from segment to segment costs .
Find the cheapest way to fertilise all the potatoes.
입력
The length of the furrow is given in the first line.
Each of the remaining lines contain two integers and – the amount of fertiliser unit and the amount of potatoes planted in segment . The segments are given in the increasing order of .
출력
Output the smallest possible cost of fertilising all the planted potatoes.
예제
예제 1
6 1 2 0 0 2 0 0 0 0 0 0 1
5
예제 2
7 2 0 2 0 2 0 0 5 2 0 2 0 2 0
6