Balloons

Time limit1sMemory limit128 MB

Problem

During a programming contest, balloons are handed out to teams as they solve problems, which can pose logistical challenges. One contest site keeps two rooms, A and B, each stocked with balloons. N teams attend the contest, each seated at a different location: some are closer to room A, some closer to room B, and some equidistant.

Given how many balloons each team needs, and each team's distance to room A and to room B, determine the minimum total distance that must be travelled to deliver all balloons to their teams, assuming the balloons are allocated optimally between the two rooms. All balloons are identical, and a team's balloons may be sourced from either room in any combination.

Input

The input contains several test cases. Each test case begins with a line of three integers:

N A B

where N is the number of teams ($1 \le N \le 1000$), and A and B are the number of balloons stocked in rooms A and B respectively ($0 \le A, B \le 10000$). Each of the next N lines contains three integers describing one team:

K DA DB

where K is the total number of balloons this team needs, DA is the team's distance from room A, and DB is the team's distance from room B ($0 \le DA, DB \le 1000$). You may assume there are always enough balloons, i.e. the sum of all K values is at most $A + B$. The input ends with a line containing three 0s.

Output

For each test case, print a single integer: the minimum total distance that must be travelled to deliver all balloons. Count only the outbound trip from room A or room B to a team; do not count a runner's return trip. Print each answer on its own line, with no extra spaces and no blank lines between answers.