#ABC263E. [ABC263E] Sugoroku 3

[ABC263E] Sugoroku 3

Score : 500500 points

Problem Statement

There are NN squares called Square 11 though Square NN. You start on Square 11.

Each of the squares from Square 11 through Square N1N-1 has a die on it. The die on Square ii is labeled with the integers from 00 through AiA_i, each occurring with equal probability. (Die rolls are independent of each other.)

Until you reach Square NN, you will repeat rolling a die on the square you are on. Here, if the die on Square xx rolls the integer yy, you go to Square x+yx+y.

Find the expected value, modulo 998244353998244353, of the number of times you roll a die.

Notes

It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented PQ\frac{P}{Q} using two coprime integers PP and QQ, there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N2×1052 \le N \le 2 \times 10^5
  • 1AiNi(1iN1)1 \le A_i \le N-i(1 \le i \le N-1)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots AN1A_{N-1}

Output

Print the answer.

3
1 1
4

The sought expected value is 44, so 44 should be printed.

Here is one possible scenario until reaching Square NN:

  • Roll 11 on Square 11, and go to Square 22.
  • Roll 00 on Square 22, and stay there.
  • Roll 11 on Square 22, and go to Square 33.

This scenario occurs with probability 18\frac{1}{8}.

5
3 1 2 1
332748122