cho.sh
Notes
Loading...

Lecture Tour

Time limit

2s

Memory limit

128 MB

Problem

An academic has received lecture requests from n universities, where 0 ≤ n ≤ 10,000. Each university offers a fee p, where 1 ≤ p ≤ 10,000, if the lecture is given within d days, where 1 ≤ d ≤ 10,000. The values p and d may differ for each university.

The academic can give at most one lecture per day. Determine the maximum total fee the academic can earn.

Input

The first line contains the integer n. Each of the next n lines contains two integers p and d, the offered fee and the deadline in days.

Output

Print the maximum total fee that can be earned.