Problem C
Nine Packs

“It’s like how hot dogs come in packs of ten, and buns come in packs of eight or twelve — you have to buy nine packs to make it come out even.”
This is a quote from the 1986 movie, “True Stories”, and
it’s true; well, almost true. You could buy four packs of
For this problem, you’ll determine the fewest packs you need to buy to make hotdogs and buns come out even, given a selection of different bun and hotdog packs available for purchase.
Input
The first input line starts with an integer,
Output
If it’s not possible to purchase an equal number of one or more hotdogs and buns, just output “impossible”. Otherwise, output the smallest number of total packs you can buy (counting both hotdog and bun packs) to get exactly the same number of hotdogs and buns.
Sample Input 1 | Sample Output 1 |
---|---|
4 10 10 10 10 10 8 8 8 12 12 12 8 8 12 12 |
4 |
Sample Input 2 | Sample Output 2 |
---|---|
4 7 7 14 7 3 11 22 11 |
impossible |