SAWMILL - Two Swamills

题目描述

There are ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/169265ff2535c9e3f13c7674d3e988cc0267cb40.png) old trees planted along a road that goes from the top of a hill to its bottom. Local government decided to cut them down. In order not to waste wood each tree should be transported to a sawmill. Trees can be transported only in one direction: downwards. There is a sawmill at the lower end of the road. Two additional sawmills can be built along the road. You have to decide where to build them, as to minimize the cost of transportation. The transportation costs one cent per meter, per kilogram of wood.

输入输出格式

输入格式


The first line of the input contains one integer ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/169265ff2535c9e3f13c7674d3e988cc0267cb40.png) - the number of trees (![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/39d123d9666a5368607c334c39551f8fe8d44c3d.png)). The trees are numbered ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/d9711b97ba9f508e0ed4272f6da612345b84abf2.png), starting from the top of the hill and going downwards. Each of the following ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/169265ff2535c9e3f13c7674d3e988cc0267cb40.png) lines contains two positive integers separated by single space. Line ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/41ea46b88ea2ca2e17752da2b356a32d4ab8a214.png) contains: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/7be1e2709dd58590800ab1674decf951e1eede16.png) - weight (in kilograms) of the ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/af121dc60b0f474c5ebf06392d630180cf0b86f7.png)-th tree and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/1d96ba5e0603bf41b4053c4c1174c50360450990.png) - distance (in meters) between trees number ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/af121dc60b0f474c5ebf06392d630180cf0b86f7.png) and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/41ea46b88ea2ca2e17752da2b356a32d4ab8a214.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/ecd08032c034988ca32ac80467023c3857df6682.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/e61bd3f1dd002794d0415bcf48ad8b7cd1e296e8.png). The last of these numbers, ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/801c093dcd7085875f69188d0d86569bf423c039.png), is the distance from the tree number ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/169265ff2535c9e3f13c7674d3e988cc0267cb40.png) to the lower end of the road. It is guaranteed that the total cost of transporting all trees to the sawmill at the end of the road is less than ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP17877/bef967db0abb57bb77165989140ef0d2c05dac4b.png) cents.

输出格式


The first and only line of output should contain one integer: the minimum cost of transportation.

输入输出样例

输入样例 #1

9
1 2
2 1
3 3
1 1
3 2
1 6
2 1
1 2
1 1

输出样例 #1

26