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.StringTokenizer;

public class main19B {
    public static PrintWriter out = new PrintWriter(System.out);
    public static FastScanner enter = new FastScanner(System.in);

    public static void main(String[] args) throws IOException {
        solve();
        out.close();
    }
    static long [][]dp;
    static boolean [][]was;
    static int[] t;
    static long[] c;
    static int n;
    private static void solve() throws IOException {
        n=enter.nextInt();
        t=new int[n];
        c=new long[n];
        dp=new long[n][4001];
        was=new boolean[n][4001];
        long ans=0;
        for (int i = 0; i < n; i++) {
            t[i]=enter.nextInt();
            c[i]=enter.nextInt();
            ans+=c[i];
        }
        mem(0,0);
        out.println(ans-dp[0][0]);
    }

    private static void mem(int pos, int balance) {
        if(was[pos][func(balance)])return;
        if(pos==n-1){
            if(balance>=1){
                dp[pos][balance]=c[pos];
            }
            else if(balance+t[pos]>=0){
                dp[pos][func(balance)]=0;
            }
            else{
                dp[pos][func(balance)]=-1;
            }
            was[pos][func(balance)]=true;
            return;
        }

        mem(pos+1, balance-1);
        mem(pos+1, balance+t[pos]);
        long hh;
        dp[pos][func(balance)]=Math.max(( (hh=dp[pos+1][func(balance-1)])==-1) ?-1:hh+c[pos], dp[pos+1][func(balance+t[pos])]);
        was[pos][func(balance)]=true;
    }

    private static int func(int balance) {
        if(balance<0){
            return 2000+Math.abs(balance);
        }
        return Math.min(balance, 2000);
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer stok;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() throws IOException {
            while (stok == null || !stok.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return null;
                }
                stok = new StringTokenizer(s);
            }
            return stok.nextToken();
        }

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

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        char nextChar() throws IOException {
            return (char) (br.read());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }
    }
}
