KUMAR2019 - VALENTINE

no tags 

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 doesn'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 lines contain 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>: <answer>

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
6
0
1
2
3
4
6 Output: 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.

hide comments
utkarsha gaumat: 2019-02-15 19:05:51

This problem cant be tested error when clicking on submit

utkarsha gaumat: 2019-02-15 18:33:04

There is no submit solution button for it.
Please add the submit button.


Added by:ad
Date:2019-02-15
Time limit:0.200s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:General