Yeongseon works today, and she works tomorrow and the day after as well.
Yeongseon has been assigned n tasks. Each task can be done only inside a fixed period, and the time it takes depends on the day she starts it.
Suppose a task has period [a,b]. If she starts it on day d and it takes T days, she works from day d through day d+T−1 and finishes on day d+T−1. So she can start that task on day d only when a≤d and d+T−1≤b.
For example, take a task with period [1,5] that takes 4 days when started on day 1, 2 days on day 2, 3 days on day 3, 5 days on day 4, and 2 days on day 5. Starting on day 4 or on day 5 runs past day 5, so the task cannot finish inside its period. Starting on day 2 finishes it on day 3, which is the earliest possible.
Yeongseon handles one task at a time. If the previous task finished on day e, the next task may start on that same day e.
She does not have to do every task. Given the task information, find the largest number of tasks she can finish.