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 Kotlin (1.0.0) (judge verdict: Wrong Answer)

fun main(args: Array<String>) {
    val (k, a, b) = readLine()!!.split(" ").map{it.toLong()}

    // 単純にｋ回操作を行ったら時間切れ

    // 交換しないほうが良いケース
    if(b-a <=2) {
        print(k+1)
        return
    }

    // 交換できないケース
    if (a >= k ) {
        print(k)
        return
    }


    // 以下の手順を単純に行うのは x 場合分けして計算する

    // その他の場合は溜まり次第交換していったほうが良い，
    // A -> B 交換するたびに，新たに A -> B 交換するための枚数は貯まるので一度条件を満たせば交換し続けるのが最善


    // 交換できる & 交換したほうが良いので，まず第一回まで貯める
    var cnt = a
    var res = k - (a-1)

    // 以降は残り回数の

    cnt += if (res % 2 == 0L) {
        (b-a) * (res/2)
    } else {
        (b-a) * (res/2) + 1
    }

    print(cnt)
}