0.65 Ewelina loves baking beautiful cakes for special occasions. As a result of the quality of her work, she has received from friends and family more cake orders than she can handle, and she needs help to decide which orders to accept.
Ewelina has a list of cake orders, each described by three integers: the delivery time , the amount of time it will take her to complete the work, and the beauty of the cake she has in mind. She would like to accept the subset of cake orders that maximizes the total sum of cake beauty, taking into account that she will never work on more than one cake at once, and that she will always work on a cake as late as possible (that is, between instant and instant ) so that the cake is in the best condition when delivered.
0.33
Input consists of several cases, each one with an between 1 and , followed by triples of integers . Assume and .
For every case, print the maximum possible sum of beauty of the delivered cakes.
Input
2 10 4 1000 16 6 2000 2 10 4 1000 16 7 2000 5 900000 800000 5000 500000 100000 2000 900000 300000 2000 800000 350000 3000 300000 300000 2000
Output
3000 2000 6000