P16806 [Lanqiao Cup 2026 National Python A] Sugar Limit.
Description
Programmer Xiao Lan needs to refactor a complex project tonight. Because the workload is very intense, he must consume sugar to replenish energy and keep his brain running at high speed.
However, according to the medical checkup report at the beginning of the year, Xiao Lan’s sugar tolerance limit is $N$ grams. Once the sugar in his body exceeds this limit, he will instantly fall asleep due to high blood sugar.
At the beginning, the sugar in Xiao Lan’s body is $0$ grams.
The company has two kinds of desserts with unlimited supply:
1. Donut: each time he eats one, the sugar in his body increases by $a$ grams.
2. Iced cola: each time he drinks one can, the sugar in his body increases by $b$ grams.
To safely take in more energy, during the whole refactoring process, Xiao Lan may do jumping jacks to consume sugar (at most once). This immediately halves the current sugar in his body. If the value after halving is not an integer, discard the fractional part (i.e., take the floor; for example, $5$ grams becomes $2$ grams after halving).
During the entire sequence of operations, at any moment, the sugar in Xiao Lan’s body must not exceed the tolerance limit $N$ grams.
Now please help Xiao Lan compute: under the safety restriction above, what is the maximum number of grams of sugar he can reach in his body?
Input Format
One line contains three positive integers $N$, $a$, and $b$ separated by spaces, representing Xiao Lan’s sugar tolerance limit, the sugar increase from eating one donut, and the sugar increase from drinking one can of iced cola (unit: grams).
Output Format
Output one integer, representing the maximum sugar level (in grams) that Xiao Lan can reach within the safe range.
Explanation/Hint
### Sample Explanation
Xiao Lan can do the following operations:
1. Eat one donut, and the sugar in his body becomes $5$ grams.
2. Do jumping jacks once, and the sugar in his body is instantly halved to $2$ grams.
3. Drink one can of iced cola, and the sugar in his body increases by $6$ grams, reaching $8$ grams.
At this point, it exactly reaches the tolerance limit $8$ and cannot be increased further, so output $8$.
### Constraints
For $30\%$ of the testdata, $1 \le N \le 500$.
For all testdata, $1 \le N \le 10^6$, $1 \le a, b \le N$.
Translated by ChatGPT 5