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

public class B {        
        
    static class item implements Comparable<item>{
        
        int time;
        int price;
        item(int t,int c){
            
            time = t;
            price = c;
        }
        @Override
        public int compareTo(item o) {
            
            long lcm = (long)price*o.price/gcd(price,o.price);
            long a = (lcm/price)*time;
            long c = (lcm/o.price)*o.time;
            if(a>c) return -1;
            else if(a==c){
                
                if(price<o.price) return -1;
                else return 1;
            }
            return 1;
        }
        
    }
        private BufferedReader in;  
        private StringTokenizer st;
        
        boolean []removed;
        item[]it;
        void solve() throws IOException{
        int n = nextInt();
        it = new item[n];
        removed = new boolean[n];
        int cost = 0;
        for (int i = 0; i < it.length; i++) {
            it[i] = new item(nextInt(), nextInt());
            cost+=it[i].price;
        }
        Arrays.sort(it);        
        for (int i = 0; i < it.length; i++) {
            
            if(removed[i]) continue;
            removed[i] = true;
            for (int j = 0; j < it[i].time; j++) {
                
                cost-=getMax(i);
            }
        }
        System.out.println(cost);
                    
        }
        
        int getMax(int currentindex){
            
            int max = 0;
            int maxi = -1;
            for (int i = 0; i < it.length; i++) {
                if(i==currentindex||removed[i]) continue;
                if(it[i].price>max){
                    max = it[i].price;
                    maxi = i;
                }
            }
            if(maxi!=-1){
                
                removed[maxi] = true;
                
            }           
            return max;
            
        }
        B() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));          
            eat("");
            solve();            
        }

        private void eat(String str) {
            st = new StringTokenizer(str);
        }

        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                String line = in.readLine();
                if (line == null) {
                    return null;
                }
                eat(line);
            }
            return st.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());
        }

        public static void main(String[] args) throws IOException {         
            new B();
        }
        

        static int gcd(int a,int b){
            if(b>a) return gcd(b,a);
            if(b==0) return a;
            return gcd(b,a%b);
        }

}
