atcoder#ABC298E. [ABC298E] Unfair Sugoroku

[ABC298E] Unfair Sugoroku

Score : 500500 points

Problem Statement

Takahashi and Aoki will play a game of sugoroku. Takahashi starts at point AA, and Aoki starts at point BB. They will take turns throwing dice. Takahashi's die shows 1,2,,P1, 2, \ldots, P with equal probability, and Aoki's shows 1,2,,Q1, 2, \ldots, Q with equal probability. When a player at point xx throws his die and it shows ii, he goes to point min(x+i,N)\min(x + i, N). The first player to reach point NN wins the game. Find the probability that Takahashi wins if he goes first, modulo 998244353998244353.

How to find a probability modulo $998244353$ It can be proved that the sought probability is always rational. Additionally, the constraints of this problem guarantee that, if that probability is represented as an irreducible fraction \frac{y}{x}, then x is indivisible by 998244353.
Here, there is a unique integer z between 0 and 998244352 such that xz \equiv y \pmod {998244353}. Report this z.

Constraints

  • 2N1002 \leq N \leq 100
  • 1A,B<N1 \leq A, B < N
  • 1P,Q101 \leq P, Q \leq 10
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN AA BB PP QQ

Output

Print the answer.

4 2 3 3 2
665496236

If Takahashi's die shows 22 or 33 in his first turn, he goes to point 44 and wins. If Takahashi's die shows 11 in his first turn, he goes to point 33, and Aoki will always go to point 44 in the next turn and win. Thus, Takahashi wins with the probability 23\frac{2}{3}.

6 4 2 1 1
1

The dice always show 11. Here, Takahashi goes to point 55, Aoki goes to point 33, and Takahashi goes to point 66, so Takahashi always wins.

100 1 1 10 10
264077814