cho.sh
Notes
Loading...

Infinite Sequence 2

Time limit

10s

Memory limit

512 MB

Problem

Sequence A is defined for every integer i as follows.

  • If i ≤ 0, then A_i = 1.
  • If i ≥ 1, then A_i = A_{⌊i / P⌋ - X} + A_{⌊i / Q⌋ - Y}.

Given integers N, P, Q, X, and Y, compute A_N.

Input

The first line contains five integers N, P, Q, X, and Y.

Output

Print the value of A_N on one line.

Constraints

  • 0 ≤ N ≤ 10^13
  • 2 ≤ P, Q ≤ 10^9
  • 0 ≤ X, Y ≤ 10^9

Hint

⌊x⌋ denotes the greatest integer less than or equal to x.