Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Let's Go Rolling!

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputOn a number axis directed from the left rightwards, *n* marbles with coordinates *x*_{1}, *x*_{2}, ..., *x*_{n} are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number *i* is equal to *c*_{i}, number *c*_{i} may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands:

- the sum of the costs of stuck pins;
- the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions.

Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.

Input

The first input line contains an integer *n* (1 ≤ *n* ≤ 3000) which is the number of marbles. The next *n* lines contain the descriptions of the marbles in pairs of integers *x*_{i}, *c*_{i} ( - 10^{9} ≤ *x*_{i}, *c*_{i} ≤ 10^{9}). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.

Output

Output the single number — the least fine you will have to pay.

Examples

Input

3

2 3

3 4

1 2

Output

5

Input

4

1 7

3 1

5 10

6 1

Output

11

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/25/2017 00:29:48 (c3).

Desktop version, switch to mobile version.
User lists

Name |
---|