fairgame

Time limit: 0.15s Memory limit: 256MB Input: Output:

Task

Alice and Bob are playing a game. They have a pile of NN rocks. Alice makes the first move, then Bob does the second, and so on. In each turn, the player that has to move takes at least 11 rock and maximum KK rocks. If one takes an odd number of rocks, then they have to pay MM dollars. When the pile is empty, the player who made the last move gets PP dollars and the other one gets QQ dollars. After the game ends, Alice will end up with an amount of dollars, let's call it XX, and Bob will end up with another amount of dollars, let's call it YY. Knowing that they play optimally, which means Alice wants to maximize the number XYX - Y Bob wants to minimize this number, then find out XYX - Y after the game ends.

Input data

The first line will contain the values of NN, KK, MM, PP, QQ in this order.

Output data

The first line will contain the value of the difference in dollars between Alice and Bob.

Constraints and clarifications

  • 1N,K,M,P,Q51061 \leq N, K, M, P, Q \leq 5 \cdot 10^6
  • For 3030 points, N4 000N \leq 4 \ 000
  • For 1010 more points, N10 000N \leq 10 \ 000, K900K \leq 900
  • For 2020 more points, N10 000N \leq 10 \ 000

Example

stdin

6 3 5 4 2

stdout

2

Log in or sign up to be able to send submissions!