spoj#KUMAR2019. VALENTINE
VALENTINE
Kumar was very excited for his Valentine's day but at the same time he was afraid about the demands of his date.
All was going good, but at last they ordered wine, waiter offered x and y unit glasses, here she got him, she said "I will drink only z unit, it's a crime not to eat a rare steak without a good glass of red wine".
Now to get the z unit out of x and y unit of glasses, Kumar starts shuffling wine from one glass to another, as it will impress her, he had to do it quick, he does't want to get embarrassed by calling for other glasses, or making other excuses.
Guess how he managed to serve the wine.
Input
First line contains x and y. Next line contains q number of possible values of z his date can demand.
Next q line contains values of z.
Output
For each z, output the minimum step required to serve z unit of wine with the available glasses even if he needs to waste some or output "Damn!!" if he can't serve.
Format for output
Case <ith query>: <output>
Constraints
0 <= x,y <= 1000 (Yes, 0 mean waiter doesn't even serve the glasses).
0 <= z <= 2000 (0 means, she doesn't wanted to drink at all, ordering wine was just the Kumar's choice).
Example
Input: 2 3</p>
6
0
1
2
3
4
6Output: Case 1: 0
Case 2: 2
Case 3: 1
Case 4: 1
Case 5: 3
Case 6: Damn!!
Explanation:
Case 2: (0,3) -> (2,1)
Case 5: (2,0) -> (0,2) -> (2,2)
Case 6: He can't serve.