UFPT2015H - Balloons

no tags 

As you may know, balloons are handed out during ACM contests to teams as they solve problems. However, this sometimes presents logistical challenges. In particular, one contest hosting site maintains two rooms, A and B, each containing a supply of balloons. There are N teams attending the contest at that site, each sitting at a different location. Some are closer to room A, others are closer to room B, and others are equally distant. Given the number of balloons needed by each team and the distance from each team to room A, and to room B, what is the minimum total possible distance that must be traveled by all balloons as they are delivered to their respective teams, assuming they are allocated in an optimal fashion from rooms A and B? For the purposes of this problem, assume that all of the balloons are identical.

Input

There will be several test cases in the input. Each test case will begin with a line with three integers: N A B.

Where N is the number of teams (1 ≤ N ≤ 1,000), and A and B are the number of balloons in rooms A and B, respectively (0 ≤ A,B ≤ 10,000). On each of the next N lines there will be three integers, representing information for each team: K DA DB.

Where K is the total number of balloons that this team will need, DA is the distance of this team from room A, and DB is this team’s distance from room B  (0 ≤ DA,DB ≤ 1,000). You may assume that there are enough balloons – that is, Σ(K’s) ≤ A+B. The input will end with a line with three 0s.

Output

For each test case, output a single integer, representing the minimum total distance that must be traveled to deliver all of the balloons. Count only the outbound trip, from room A or room B to the team. Don’t count the distance that a runner must travel to return to room A or room B. Print each integer on its own line with no spaces. Do not print any blank lines between answers.

Example

Input: 
3 15 35
10 20 10 
10 10 30
10 40 10 
0 0 0

Output: 
300


Added by:Cormac
Date:2015-09-20
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY
Resource:2010 ACM ICPC Southeast Regional Programming Contest