CSES - Aalto Competitive Programming 2024 - wk3 - Wed - Box stack I
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Uolevi is working at a giant megacorporation warehouse. He stacks boxes so that they take up less area. There are nn boxes numbered 1,2,,n1,2,\dots,n. The ii-th box has weight wi kgw_i\ kg, can hold ci kgc_i\ kg above it and has height hih_i. Find the height of the tallest possible tower Uolevi can construct.

Input

The first line contains a single integer nn. The ii-th of the next nn lines contains three integers wiw_i, cic_i and hih_i.

Output

Print the maximum height of the tallest possible tower.

Constraints

  • 1n20001 \leq n \leq 2000
  • 1wi,ci,hi20001 \leq w_i, c_i, h_i \leq 2000

Example 1

Input:

2
2 2 3
3 1 4

Output:

4

Example 2

Input:

5
1 4 6
5 5 1
2 4 2
1 3 9
5 2 3

Output:

18