Jaroslav owns a small courier service. He has recently got and introduced a new system of processing parcels. Each parcel is a box, the box has its weight and strength. The system works as follows. It originally has an empty platform where you can put boxes by the following rules:
-
If the platform is empty, then the box is put directly on the platform, otherwise it is put on the topmost box on the platform.
-
The total weight of all boxes on the platform cannot exceed the strength of platform S at any time.
-
The strength of any box of the platform at any time must be no less than the total weight of the boxes that stand above.
You can take only the topmost box from the platform.
The system receives
n parcels, the
i-th parcel arrives exactly at time
ini, its weight and strength are equal to
wi and
si, respectively. Each parcel has a value of
vi bourles. However, to obtain this value, the system needs to give the parcel exactly at time
outi, otherwise Jaroslav will get 0 bourles for it. Thus, Jaroslav can skip any parcel and not put on the platform, formally deliver it at time
ini and not get anything for it.
Any operation in the problem is performed instantly. This means that it is possible to make several operations of receiving and delivering parcels at the same time and in any order.
Please note that the parcel that is delivered at time
outi, immediately gets outside of the system, and the following activities taking place at the same time are made without taking it into consideration.
Since the system is very complex, and there are a lot of received parcels, Jaroslav asks you to say what maximum amount of money he can get using his system.