Deadline Homework


You have nn homework assignments to choose from. Each assignment takes exactly one hour to complete.

Assignment ii has a deadline did_i and a score sis_i. If you spend one full hour on it and finish by the end of hour did_i, you earn sis_i points. Otherwise, you earn nothing for that assignment.

You can work on at most one assignment in each hour, and you do not have to complete every assignment.

What is the maximum total score you can earn?

Input

The first line contains an integer nn, the number of assignments.

The next nn lines each contain two integers did_i and sis_i, the deadline and score of one assignment.

Output

Print one integer: the maximum total score you can earn.

Constraints

  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • 1≤di≤1091 \le d_i \le 10^9
  • 1≤si≤1091 \le s_i \le 10^9

Example 1

Input 1
4
4 70
1 80
1 30
2 100
Output 1
250
Explanation

One optimal schedule is:

  • hour 11: take the assignment with deadline 11 and score 8080
  • hour 22: take the assignment with deadline 22 and score 100100
  • hour 33: take the assignment with deadline 44 and score 7070

This earns 80+100+70=25080 + 100 + 70 = 250 points.

Example 2

Input 2
5
1 10
1 20
1 30
1 40
1 50
Output 2
50

Example 3

Input 3
6
2 50
2 10
3 20
3 30
3 40
100 60
Output 3
180

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.