A kangaroo is in a certain position , and he wants to reach the position 1. Spending units of energy, the kangaroo can make a step to the position . If is an even number, spending units of energy, the kangaroo can jump to the position .
Your task is to write a program that given the initial position , the constant and the constant , prints the minimal cost of energy in order to the kangaroo goes from to 1.
The input is a sequence of at most 10000 lines, each one with , and in this order, separated by spaces. All the numbers of the input are integers strictly positive. A special line with the zeros indicates the end of the input and must not be processed.
For each line of the input, your program must print the minimal cost of going from to 1 making steps of cost and jumps of cost . This number will always be less than .
(30 points) Solving all the inputs of instance.
(70 points) Solving all the other inputs.
Input
1 200 200 10 1 100 10 100 1 1024 1 1 1024 1 5 1234567 3 43 0 0 0
Output
0 9 103 10 42 766