#ARC150D. [ARC150D] Removing Gacha

[ARC150D] Removing Gacha

Score : 700700 points

Problem Statement

We have a rooted tree with NN vertices numbered 11 to NN. Vertex 11 is the root of the tree, and the parent of vertex i (2i)i\ (2\leq i) is vertex pip_i.

Each vertex has a color: black or white. Initially, all vertices are white.

In this rooted tree, vertex ii is said to be good when all vertices on the simple path connecting vertices 11 and ii (including vertices 11 and ii) are black, and bad otherwise.

Until all vertices are black, let us repeat the following operation: choose one vertex from the bad vertices uniformly at random, and repaint the chosen vertex black.

Find the expected value of the number of times we perform the operation, modulo 998244353998244353.

The definition of the expected value modulo $998244353$

It can be proved that the sought expected value is always a rational number. Additionally, when that value is represented as an irreducible fraction PQ\frac{P}{Q}, it can also be proved that Q≢0(mod998244353)Q \not \equiv 0 \pmod{998244353}. Therefore, there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P \pmod{998244353} and 0R<9982443530 \leq R < 998244353. Find this RR.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1pi<i1 \leq p_i < i
  • All values in the input are integers.

Input

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

NN

p2p_2 p3p_3 \dots pNp_{N}

Output

Print the answer.

4
1 1 3
831870300

Consider a case where the first three operations have chosen vertices 11, 22, and 44 in this order. Then, vertices 11 and 22 are good, but vertex 44 is still bad since vertex 33, an ancestor of vertex 44, is white. Thus, the fourth operation will choose vertex 33 or 44 uniformly at random.

The expected value of the number of times we perform the operation is 356\displaystyle \frac{35}{6}.

15
1 2 1 1 4 5 3 3 5 10 3 6 3 13
515759610