Tasks and deadlines

Given n tasks with their deadlines and the profit you’ll get by completing that task before the deadline, you’d like to know what the maximum total profit is you can get. Completing each task takes 1 day. If you don’t complete a task before the deadline, you don’t get anything.
You start from day 1. How much profit can you make?

Input

The first line of the input contains a single integer n (1 ≀ n ≀ ) the number of tasks.
The next n lines contain space-separated pairs of integers (1 ≀ , ≀ ) the deadline and the profit for completing each task.

Output

The program should print the maximum total profit you can have.

Examples

Input
Output
4 4 10 1 3 2 7 2 3
20
5 1 1 4 100 4 200 4 300 4 200
800

Explanation

  1. 10 + 3 + 7
    1. First, perform the task with the deadline 1 β‡’ earn 3
    2. Then perform the task with the deadline 2 β‡’ earn 7
    3. Then perform the task with the deadline 4 β‡’ earn 10
  1. 100 + 200 + 300 + 200 (only perform tasks with deadline 4)
    1. Perform the task with a profit of 100
    2. Perform the task with a profit of 200
    3. Perform the task with a profit of 300
    4. Perform the task with a profit of 200
Β 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in