Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-muddatli-buyurtmalar

Orders with deadlines

Medium 1000 ms 128 MB 53%
Share

A craftsman has received $n$ orders. Each order takes exactly one day, and the craftsman completes only one order per day; work starts on day $1$. If the $i$-th order is completed no later than day $d_{i}$ (that day is also fine), the craftsman earns $p_{i}$ soums; nothing is paid for a late order, and it may be skipped altogether. What is the largest amount the craftsman can earn?

A day axis: order deadlines and the days they are placed on; the chosen orders are highlighted

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains two positive integers: $d_{i}$ and $p_{i}$.

Output

One integer — the largest total income.

Note

$1 \le n \le 10^{5}$
$1 \le d_{i} \le 10^{5}$
$1 \le p_{i} \le 10^{9}$

Examples

Input #1
5
2 100
1 19
2 27
1 25
3 15
Output #1
142
Input #2
1
1 5
Output #2
5

Sign in to submit a solution

Signing up is free and takes a minute.