Guessing Game

Identify a hidden integer from 1 to n with adaptive subset questions where each NO costs a and each YES costs b while minimizing the worst-case total.

Hard8Dynamic programmingBinary searchMathNo attempts yetTime limit1sMemory limit256 MB

Problem

John and George play the following game. John picks one integer xx from the set An={1,2,3,,n}A_n = \{1, 2, 3, \ldots, n\}, and George has to find out which integer it is. The game runs in moves 1,2,3,1, 2, 3, \ldots. On move kk George picks a subset BkB_k of AnA_n, and John answers YES if xx belongs to BkB_k and NO otherwise. For a NO answer George pays John aa euros, and for a YES answer he pays bb euros.

George hears each answer before he picks the next subset. Among all strategies that always identify xx, find the one whose largest possible total payment is smallest, and compute that payment.

Input

The first line contains three integers nn, aa, and bb, separated by spaces.

Output

Print one integer, the minimum amount of euros George has to pay.

Constraints

  • 1<n<10181 < n < 10^{18}
  • 0<a,b<10000 < a, b < 1\,000

Hint

For n=5n = 5, a=1a = 1, b=2b = 2 George can find xx for 4 euros.

George first picks B1={1,2}B_1 = \{1, 2\}.

  • If John answers YES, George pays 2 euros and picks B2={1}B_2 = \{1\}. On another YES he pays 2 more euros and the game ends (x=1x = 1). On NO he pays 1 more euro and the game ends (x=2x = 2).
  • If John answers NO, George pays 1 euro and picks B2={3}B_2 = \{3\}. On YES he pays 2 more euros and the game ends (x=3x = 3). On NO he pays 1 more euro and picks B3={4}B_3 = \{4\}. On YES he pays 2 more euros and the game ends (x=4x = 4). On NO he pays 1 more euro and the game ends (x=5x = 5).

The most expensive outcomes are x=1x = 1 and x=4x = 4, and both cost 4 euros.