Under construction

Still being built. Things may change

Bank Robbery 2

Interview

Time limit1sMemory limit256 MB

Summary
Given banks at positions X_i that open at time T_i, find the maximum total money Siwoo can rob while moving only rightward from a chosen start.
Level

Easy3 of 10

Topics
Hash map, Implementation
Solved
No attempts yet

Problem

Siwoo, a professional bank robber, wants to rob banks. Along the straight path he runs on, there are NN banks. The ii-th bank is at a distinct coordinate XiX_i on the line, and its door opens only when the time is exactly TiT_i, so he can enter only then. Robbing this bank yields CiC_i won.

Siwoo starts at an arbitrary integer coordinate on the line and moves. While he moves, his coordinate must not decrease (he may stop as long as he wants). Time starts at 00, and whenever the coordinate increases by 11, the time increases by 11.

Whenever Siwoo meets a bank whose door is open, he must rob it and move on. He is very skilled, so robbing a bank never increases the time at all.

Print the maximum amount of money Siwoo can obtain when he starts at a suitable position.

Input

The first line contains NN. (1≤N≤300 0001 \le N \le 300\,000)

From the second line onward, the next NN lines each contain integers Xi,Ti,CiX_i, T_i, C_i in the order where ii and XiX_i increase. (0≤Xi,Ti,Ci≤1090 \le X_i, T_i, C_i \le 10^9)

All XiX_i are distinct.

Output

Print the maximum amount of money Siwoo can obtain.

Examples3

  1. Example 1

    Input
    1
    0 3 4
    
    Expected output
    4
    
  2. Example 2

    Input
    2
    0 0 10
    1 0 3
    
    Expected output
    10
    
  3. Example 3

    Input
    5
    0 2 4
    1 6 1
    2 4 4
    3 8 10
    4 5 2
    
    Expected output
    18