Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.

Input

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

Examples

Input

4
2 10
0 20
1 5
1 3


Output

8


Input

3
0 1
0 10
0 100


Output

111
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * _19B
 * O(2*2000*n) time
 * θ(2*2000*n) space
 *
 * @author artyom
 */
public class _19B implements Runnable {
    private static final long MAX_VALUE = 100_000_000_000_000L;
    private BufferedReader in;
    private PrintStream out;
    private StringTokenizer tok;
    private int[] t;
    private int[] c;
    private int n;
    private long[][] dp;

    private void solve() throws IOException {
        n = nextInt();
        dp = new long[n][4001];
        t = new int[n];
        c = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = nextInt();
            c[i] = nextInt();
            Arrays.fill(dp[i], -MAX_VALUE);
        }
        out.print(calc(0, 0));
    }

    private long calc(int index, int balance) {
        if (index == n) {
            return balance >= 0 ? 0 : MAX_VALUE;
        }
        if (balance >= n - index) {
            return 0;
        }
        int b = balance >= 0 ? balance : 2000 - balance;
        if (dp[index][b] == -MAX_VALUE) {
            dp[index][b] = Math.min(calc(index + 1, balance - 1), c[index] + calc(index + 1, balance + t[index]));
        }

        return dp[index][b];
    }

    //--------------------------------------------------------------
    public static void main(String[] args) {
        new _19B().run();
    }

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = System.out;
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    private String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}