Russian Dolls
Maybe you know the famous russian souvenir Russian Dolls. It looks like a set of nested wooden dolls. A doll with a smaller size is placed inside a bigger one. Let's consider all dolls taken apart. Each doll has an outer volume out[i]
which is the volume it occupies in space and an inner volume in[i]
- the volume of the empty space inside the doll. You may assume that you can put one doll inside another if the outer volume of the first doll is strictly less than the inner volume of the second one. If two or more dolls are inside another one they can't lie one near the other, they must be nested.
For each doll the cost of unit of empty space - cost[i]
is known. You must pay exactly cost[i]
for each unit of empty space which directly belongs to the i-th doll (but not to ones inside it). You may arrange the dolls the way you want as long as you are not contradicting the rules. The objective is to find an arrangement of nesting the dolls (not necessarily all of them) such that the overall cost you have to pay is minimized.
Input
First line contains an integer n (1 ≤ n ≤ 1000) which is the number of dolls you have. The i-th of the next n lines contains three integers out[i]
, in[i]
, cost[i]
(1 ≤ in[i]
≤ out[i]
≤ 1000, 1 ≤ cost[i]
≤ 1000), which are the outer volume, inner volume and the empty space cost of the i-th doll.
Output
Print a single integer p which is the minimum possible cost you should pay.