Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2240.   New Adventures in Moving
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 303   Accepted Runs: 49



Kandy is considering travelling from Tianjin to another big city by his big truck. As all we know, gas price is very high nowadays. Kandy wonders how much he will spend totally.

The truck consumes one litre of gas exactly for each kilometre when it runs. It has a C litre gas tank( 100 ≤ C ≤ 1000 ). The distance between Tianjin and the big city is D kilometres ( 1 ≤ D ≤ 100000). Along the way, there are up to 1000 gas stations. When Kandy leaves from Tianjin, the truck has 50 litres of gas in its tank.

Input

There are several test cases. For each case, the first line contains two integers C and D, the second line contains one integer N, the number of gas stations along the way( 1 ≤ N ≤ 1000). Next comes N lines, each describes one station, in non-decreasing order by distance. Each description contains three integers di, pi and mi. di is distance of the ith station from Tianjin. pi is the price of a litre of gas at that station, at most 1000. mi is the maximum gas that station can apply in litres( 1 ≤ mi ≤ 1000 ).

The last case is followed by "0 0".

Output

For each test case, output one line contains one number, the minimum cost of gas Kandy will spend along his trip. If he cannot get to the big city, in case of running out of the gas during the way, just print "impossible".

Sample Input

200 250
3
60 180 150
150 100 400
250 80 100
200 250
3
50 180 150
150 100 400
250 80 100
100 300
4
30 200 80
100 600 60
110 150 150
200 200 190
0 0

Sample Output

impossible
28000
45000



Source: TOJ 2006 Weekly Contest 7
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.2.4