cho.sh
Notes
Loading...

Cup Ramen

Time limit

2s

Memory limit

256 MB

Problem

Sangwook, a teaching assistant, gave Dongho N problems and announced how many cups of ramen Dongho would receive for solving each one. Because Dongho was extremely confident, Sangwook also assigned a deadline to each problem.

Problem number1234567
Deadline1133226
Cups of ramen6721451

In the situation above, if Dongho solves the problems in the order 2, 6, 3, 1, 7, 5, 4, then problems 2, 6, 3, and 7 are completed before their deadlines. He receives a total of 15 cups of ramen.

Find the maximum number of cups of ramen Dongho can receive. In the situation above, the maximum is 15.

Solving one problem takes exactly 1 unit of time. Every deadline is a positive integer not greater than N. The number of cups awarded for each problem, and the maximum total number of cups Dongho can receive, are positive integers less than 2^31.

Input

The first line contains the number of problems N (1 ≤ N ≤ 200,000).

Each of the next N lines contains two integers separated by a space: the deadline of the i-th problem and the number of cups of ramen received for solving it.

Output

Print the maximum number of cups of ramen Dongho can receive.