Drink Responsibly

Decide whether whole numbers of up to eight drinks can total exactly m in cost and u in alcohol, and print the lexicographically smallest purchase.

Medium6Dynamic programmingMathNo attempts yetTime limit1sMemory limit256 MB

Problem

The University of Lagado runs a beer tasting during Fresher's week. For safety the university caps how much money one student may spend, and each student sets a personal limit on the alcohol they will drink that night.

Drinks are served in one of three sizes: a litre, half a litre, or a third of a litre. One unit of alcohol is the amount contained in one litre of a drink of strength 1 percent. A drink of strength ss percent served in a size of ff litres therefore holds s×fs \times f units.

A student wants to spend all mm of their money, down to the last coin, and drink exactly uu units of alcohol. No more and no less. Any drink may be bought any number of times, including none. Decide whether such a purchase exists, and if it does, print what to buy and how many of each.

Input

The first line holds three values.

  • mm (0.01m10.000.01 \le m \le 10.00), the money available, written to two decimal places.
  • uu (0.0u20.00.0 \le u \le 20.0), the number of units aimed for, written to one decimal place.
  • dd (1d81 \le d \le 8), the number of different drinks on sale.

Each of the next dd lines holds four values separated by single spaces.

  • The name of the drink, up to 20 lowercase latin letters. The dd names are distinct.
  • Its strength, an integer percentage between 0 and 100.
  • Its size, 1/1 for a litre, 1/2 for half a litre, 1/3 for a third of a litre.
  • Its cost, a real number between 0.00 and 10.00 written to two decimal places.

Output

If no purchase spends exactly mm and delivers exactly uu units, print one line holding IMPOSSIBLE.

Otherwise print one line for every drink bought, in the order the drinks appear in the input, giving the name and then the number bought, separated by one space. A drink bought zero times is not printed.

Several purchases may work. Write cic_i for the number bought of the ii-th drink of the input, so that a purchase is the sequence (c1,c2,,cd)(c_1, c_2, \dots, c_d), and print the purchase that comes first in lexicographic order: take the smallest c1c_1, among those the smallest c2c_2, and so on to the end.

Because mm is at least 0.01, any purchase that exists buys at least one drink, so the output is never empty.