Surf

Pick waves with no wait-time overlap so the sum of fun points is as large as possible.

Medium5Dynamic programmingSortingBinary searchInterviewNo attempts yetTime limit4sMemory limit256 MB

Problem

You have taken up surfing in Florida, and you have the full schedule of today's waves. For each wave you know the minute it arrives, the fun points you earn by riding it, and how long you have to wait afterwards before you can ride again. The wait covers the ride itself plus the paddle back out to where the waves break.

If you ride the wave that arrives at minute mim_i, the next wave you ride has to arrive at minute mi+wim_i + w_i or later. Anything that arrives earlier is gone before you are back in position.

Taking the wave with the most fun points is not always best. Consider these four waves:

MinuteFun pointsWait time
2809
8502
10402
13205

Riding the waves at minutes 8, 10 and 13 earns 110 fun points. Riding the wave at minute 2 keeps you out of position until minute 11, so the only wave left is the one at minute 13, for a total of 100 fun points. The best total here is 110.

Given the complete list of waves for the day, find the largest total of fun points you can earn.

Input

The first line contains one integer nn (1n3000001 \le n \le 300\,000), the number of waves for the day.

Each of the next nn lines contains three space separated integers mim_i, fif_i and wiw_i (1mi,fi,wi1061 \le m_i, f_i, w_i \le 10^6): the minute the ii-th wave arrives, its fun points, and its wait time.

No two waves arrive at the same minute. The waves are not necessarily listed in chronological order.

Output

Print one integer on a single line, the maximum total of fun points you can earn.