Minjun works as a consultant and is preparing to resign.
He leaves on day N+1 counting from today, so he wants to handle as many consultations as he can during the N days that remain.
Minjun asked his secretary to book as many consultations as possible, and she booked one consultation per day, each with a different client.
Every consultation has a duration Ti, the number of days it takes to finish, and a payment Pi, the amount he receives once it is done.
Look at the schedule for N = 7.
The consultation booked on day 1 takes 3 days and pays 10. The consultation booked on day 5 takes 2 days and pays 15.
A single consultation can take longer than one day, so he cannot handle all of them. For example, if he starts the consultation on day 1, he cannot handle the ones on days 2 and 3. If he starts the one on day 2, he cannot handle the ones booked on days 3, 4, 5 and 6.
He is also not at the company on day N+1, so he cannot handle the consultations on days 6 and 7.
The largest profit before he resigns comes from handling the consultations on days 1, 4 and 5, and that profit is 10+20+15=45.
Write a program that computes the largest profit Minjun can earn by choosing the consultations well.