favorite We need a little bit of your help to keep things running, click on this banner to learn more


Apprentice Learning Trajectory

Abigail is an apprentice studying to become a blacksmith. She wants to plan her learning trajectory and make as many swords as possible on her way to becoming a famous expert.

There are n masters willing to host her as their apprentice. The i-th master will start working at the minute ai and end working at the minute bi, working for a total of biai minutes. During this interval of time, Abigail can work at this master's forge. She can enter and leave the forge several times and produce one or several swords upon each arrival. However, in order to produce a sword under supervision of the i-th master she has to work there for ti minutes in a row. She can't leave the sword unfinished and continue working on it upon her next arrival to this forge.

Help Abigail make an optimal plan and calculate the maximum number of swords she can produce under the supervision of n masters.


The first line contains integer n (1n200 000) - the number of masters. Each of the next n lines contains three integers ai, bi, ti (1ai < ai + tibi1018) - the start and the end time of master's work, and the time needed to make one sword in their forge.


Output the maximum number of swords Abigail can produce using the optimal learning trajectory.


Time limit 2 seconds
Memory limit 128 MiB
Input example #1
5 7 1
1 9 2
Output example #1
Input example #2
1 10 4
6 12 3
9 13 2
Output example #2
Input example #3
1 13 4
6 11 2
9 13 3
Output example #3
Source 2019 ACM NEERC, Semifinals, December 1, Problem A