CSES - Aalto Competitive Programming 2024 - wk4 - Wed - Box Stack II
  • Time limit: 3.00 s
  • Memory limit: 512 MB

Uolevi works at a giant megacorporation warehouse. Now that he has stacked all the boxes that have stuff in them, he is going to build the tallest possible pyramid from the empty boxes. There are nn boxes numbered 1,2,,n1,2,\dots,n, the ii-th of which has width xix_i, depth yiy_i and height ziz_i. A tower of boxes is called a pyramid if xixjx_i \leq x_j and yiyjy_i \leq y_j applies to all pairs of boxes (i,j)(i, j) where box ii is on top of box jj. Find the height of the tallest possible pyramid Uolevi can construct.

Input

The first line contains a single integer nn. The 𝑖𝑖-th of the next nn lines contains three integers xix_i, y𝑖y_𝑖, and ziz_i.

Output

Print the height of the tallest possible pyramid.

Constraints

  • 1n2×1051 \leq n \leq 2 \times 10^5
  • 1xi,yi,zi1091 \leq x_i, y_i, z_i \leq 10^9

Example 1

Input:

5
5 10 8
10 1 2
4 10 2
3 1 4
2 4 4

Output:

14

Example 2

Input:

10
5 2 1
10 6 10
5 5 5
4 4 2
3 7 7
2 3 5
3 7 7
9 6 7
2 5 6
6 2 8

Output:

33

Example 3

Input:

1
1000000000 1000000000 1000000000

Output:

1000000000