Problem:
Score : 400 points

Problem Statement

Snuke has one biscuit and zero Japanese yen (the currency) in his pocket.
He will perform the following operations exactly K times in total, in the order he likes:

Hit his pocket, which magically increases the number of biscuits by one.

Exchange A biscuits to 1 yen.

Exchange 1 yen to B biscuits.

Find the maximum possible number of biscuits in Snuke's pocket after K operations.

Constraints

1 \leq K,A,B \leq 10^9

K,A and B are integers.

Input

Input is given from Standard Input in the following format:

K A B

Output

Print the maximum possible number of biscuits in Snuke's pocket after K operations.

Sample Input 1

4 2 6

Sample Output 1

7

The number of biscuits in Snuke's pocket after K operations is maximized as follows:

Hit his pocket. Now he has 2 biscuits and 0 yen.

Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.

Hit his pocket. Now he has 1 biscuits and 1 yen.

Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.

Sample Input 2

7 3 4

Sample Output 2

8

Sample Input 3

314159265 35897932 384626433

Sample Output 3

48518828981938099

Solution in Haskell (GHC 7.10.3) (judge verdict: Accepted)

module Main where

import Control.Applicative
import Control.Monad

solve :: Integer -> Integer -> Integer -> Integer -> Integer
solve curr 0 _ _ = curr
solve curr 1 _ _ = curr + 1
solve curr k a b | b <= a + 2 = curr + k
                 | curr < a = solve (curr + incs) (k - incs) a b
                 | otherwise = solve (curr + (b - a) * dbls) (k - 2 * dbls) a b
    where incs = min (a - curr) k
          dbls = k `div` 2

main :: IO ()
main = do
  [k, a, b] <- (map read . words) <$> getLine
  print $ solve 1 k a b