시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB33232385.185%

문제

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.

입력

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.

출력

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.

예제 입력 1

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

예제 출력 1

300