100 atcoder#ABC180D. [ABC180D] Takahashi Unevolved

[ABC180D] Takahashi Unevolved

Score : 400400 points

Problem Statement

Iroha is into a game where you keep pets.

Iroha's pet is Takahashi. Initially, Takahashi's STR and EXP are XX and 00, respectively. These parameters increase in the following two kinds of training:

  • Go to Kakomon Gym: the STR gets multiplied by AA, and the EXP increases by 11.
  • Go to AtCoder Gym: the STR increases by BB, and the EXP increases by 11.

Takahashi evolves when his STR becomes YY or greater, but Iroha thinks that makes him less cute.

Find the maximum possible EXP of Takahashi when he is trained without letting him evolve.

Constraints

  • 1X<Y10181 \leq X < Y \leq 10^{18}
  • 2A1092 \leq A \leq 10^9
  • 1B1091 \leq B \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

XX YY AA BB

Output

Print the maximum possible EXP of Takahashi under the given situation.

4 20 2 10
2

Initially, Takahashi's STR is 44. We can make his EXP 22 in the following course of training:

  • First, go to Kakomon Gym, which makes his STR 88 and his EXP 11.
  • Then, go to AtCoder Gym, which makes his STR 1818 and his EXP 22.

On the other hand, there is no way to train him so that his EXP becomes greater than 22.

1 1000000000000000000 10 1000000000
1000000007

Watch out for overflows.