eolymp
bolt
Try our new interface for solving problems
Problems

Russian Dolls

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 outi which is the volume it occupies in space and an inner volume ini - 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 - costi is known. You must pay exactly costi 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 (1n1000) which is the number of dolls you have. The i-th of the next n lines contains three integers outi, ini, costi (1iniouti1000, 1costi1000), 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.

Time limit 2 seconds
Memory limit 256 MiB
Input example #1
3
5 4 1
4 2 2
3 2 1
Output example #1
7
Source 2013 SEERC South Eastern European Regional Programming Contest, Vinnica & Bucharest, October 12, Problem A