- 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 boxes numbered . The -th box has weight , can hold above it and has height . Find the height of the tallest possible tower Uolevi can construct.
Input
The first line contains a single integer . The -th of the next lines contains three integers , and .
Output
Print the maximum height of the tallest possible tower.
Constraints
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