G. Gathering the Problem Set
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The jury has collected $$$N$$$ candidate problems, and has only a few weeks to turn them into a contest. Problem $$$i$$$ would add $$$g_i$$$ points of quality to the set, a non-negative integer.

Preparing a problem is not only writing the statement. It also needs tests, a validator, a checker and at least two independent solutions, so one problem takes a full working day of the whole jury.

Every candidate problem also has an author who is available only for a limited time. Problem $$$i$$$ must be finished on day $$$d_i$$$ at the latest, where $$$d_i$$$ is a positive integer.

The jury works on days $$$1,2,3,\ldots$$$ and can prepare at most one problem per day, and no problem can be prepared twice. If problem $$$i$$$ is prepared on day $$$t$$$, then $$$t \le d_i$$$ must hold.

The jury may also drop any candidate problem. Find the maximum total quality of the final problem set.

Input

The first line contains one integer $$$N$$$ ($$$1 \le N \le 2 \cdot 10^5$$$) — the number of candidate problems.

Each of the next $$$N$$$ lines contains two integers $$$g_i$$$ and $$$d_i$$$ ($$$0 \le g_i \le 10^9$$$, $$$1 \le d_i \le 10^9$$$) — the quality and the last allowed day of problem $$$i$$$.

Output

Print one integer — the maximum total quality.

Examples
Input
5
20 1
2 1
10 2
100 2
8 3
Output
128
Input
4
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
Output
4000000000
Input
4
5 1
6 1
4 2
10 2
Output
16
Note

In the first example, the problems with quality $$$20$$$, $$$100$$$, and $$$8$$$ can be prepared on days $$$1$$$, $$$2$$$, and $$$3$$$, respectively.

In the third example, only one of the two problems with last allowed day $$$1$$$ can be prepared. Choosing the problems with quality $$$6$$$ and $$$10$$$ is optimal.