Score : $500$ points
There are $N$ squares called Square $1$ though Square $N$. You start on Square $1$.
Each of the squares from Square $1$ through Square $N-1$ has a die on it. The die on Square $i$ is labeled with the integers from $0$ through $A_i$, each occurring with equal probability. (Die rolls are independent of each other.)
Until you reach Square $N$, you will repeat rolling a die on the square you are on. Here, if the die on Square $x$ rolls the integer $y$, you go to Square $x+y$.
Find the expected value, modulo $998244353$, of the number of times you roll a die.
It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, there is a unique integer $R$ such that $R \times Q \equiv P\pmod{998244353}$ and $0 \leq R \lt 998244353$. Find this $R$.
Input is given from Standard Input in the following format:
$N$ $A_1$ $A_2$ $\dots$ $A_{N-1}$
Print the answer.
3 1 1
4
The sought expected value is $4$, so $4$ should be printed.
Here is one possible scenario until reaching Square $N$:
This scenario occurs with probability $\frac{1}{8}$.
5 3 1 2 1
332748122