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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public final class CheckoutAssistant
{
    public static void main(String[] args)
    {
        new CheckoutAssistant(System.in, System.out);
    }

    private static class Solver
    {
        static final long INF = (long) 1e15;
        int n;
        Item[] items;
        long[][] dp;
        InputReader in;
        PrintWriter out;

        void solve() throws IOException
        {
            n = in.nextInt();
            items = new Item[n];
            dp = new long[n + 1][n + 1];

            for (int i = 0; i < n; i++)
                items[i] = new Item(in.nextInt() + 1, in.nextInt());

            iterative();
        }

        void iterative()
        {
            for (int i = 0; i <= n; i++)
                Arrays.fill(dp[i], INF);

            for (int i = 0; i <= n; i++)
                dp[i][0] = 0;

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    int left = Math.max(0, j - items[i - 1].time);
                    int ind = Math.min(n, j + items[i - 1].time);

                    dp[i][j] = Math.min(dp[i - 1][j], dp[i - 1][left] + items[i - 1].cost);
                    dp[i][ind] = Math.min(dp[i][ind], dp[i][j]);
                }
            }

            out.println(dp[n][n]);
        }

        class Item
        {
            int time, cost;

            Item(int time, int cost)
            {
                this.time = time;
                this.cost = cost;
            }

        }

        Solver(InputReader in, PrintWriter out)
        {
            this.in = in;
            this.out = out;
        }

    }

    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        int nextInt()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        void close()
        {
            try
            {
                stream.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

        InputReader(InputStream stream)
        {
            this.stream = stream;
        }

    }

    private CheckoutAssistant(InputStream inputStream, OutputStream outputStream)
    {
        // uncomment below line to change to BufferedReader
        // BufferedReader in = new BufferedReader(new
        // InputStreamReader(inputStream));
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver(in, out);

        try
        {
            solver.solve();
            in.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        out.flush();
        out.close();
    }

}