Under construction

Still being built. Things may change

Fruit Feast

Interview

Time limit2sMemory limit512 MB

Summary
Eat unlimited fruits that add A or B without passing T, using at most one halving, to reach the largest fullness.
Level

Medium5 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

Bessie has broken into Farmer John's house again. In the kitchen she found a pile of lemons and a pile of oranges, and there are so many of each that you can treat the supply as unlimited. She plans to eat as much as she can.

Bessie's fullness can never go above TT. Eating one orange raises her fullness by AA, and eating one lemon raises it by BB. She refuses any fruit that would push her fullness past TT.

Bessie can also drink water at most one time. Drinking water immediately cuts her fullness in half, rounded down.

Find the largest fullness Bessie can reach.

Input

The first and only line contains three integers TT, AA, and BB, separated by spaces. (1≤T≤5 000 0001 \le T \le 5\,000\,000, 1≤A,B≤T1 \le A, B \le T)

Output

Print the largest fullness Bessie can reach, on one line.

Examples2

  1. Example 1

    Input
    8 5 6
    
    Expected output
    8
    
  2. Example 2

    Input
    17 6 6
    
    Expected output
    15