Jumping kangaroo

A kangaroo is in a certain position n1n \ge 1, and he wants to reach the position 1. Spending xx units of energy, the kangaroo can make a step to the position n1n - 1. If nn is an even number, spending yy units of energy, the kangaroo can jump to the position n/2n/2.

Your task is to write a program that given the initial position nn, the constant xx and the constant yy, prints the minimal cost of energy in order to the kangaroo goes from nn to 1.

Input

The input is a sequence of at most 10000 lines, each one with n<108n<10^8, x<105x<10^5 and y<105y<10^5 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.

Output

For each line of the input, your program must print the minimal cost of going from nn to 1 making steps of cost xx and jumps of cost yy. This number will always be less than 10810^8.

Score

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:52:56.087Z

© Jutge.org, 2006–2026.
https://jutge.org