eolymp
bolt
Try our new interface for solving problems
Problems

Random tree

Random tree

Consider the following process of building a tree T.

Initially, the tree consists of one vertex, which has the number 1.

Further vertices with numbers 2 ... n are added to the tree.

At the i-th step, a vertex with number i + 1 is added to the tree, and an edge from it to some already added vertex p (1pi), which is chosen among them randomly with equal probability.

Let V be the set of vertices already added to T.

Then let f(A) be the number of vertices T that lie either in A or on the path between any two vertices from A (perhaps both there and there).

After adding each vertex, your task is to print the sum f(A) over all sets A, which are subsets of the set of vertices already added to Tf( A) over all AV). Since the answers can be very large, print only the remainder of the answer divided by 998244353.

Input

The first line contains a single number n (2n200000) - the number of vertices in the tree after the last step.

The next line contains n - 1 integer p1, p2, ..., pn (1p [i]i), denoting adding to the graph the vertex i + 1 and the edge between pi and i + 1, respectively . It is guaranteed that pi is chosen randomly with equal probability among the numbers from 1 to i.

Output

Print n - 1 integer - the remainders from division (Σ f(A) over all AV) by *998244353 * after adding each vertex.

prb11054.gif

Time limit 1 second
Memory limit 128 MiB
Input example #1
5
1 1 1 1
Output example #1
4 13 36 91 
Input example #2
7
1 2 3 4 5 6
Output example #2
4 13 38 103 264 649 
Source 2018 Цикл Интернет-олимпиад для школьников, вторая командная олимпиада сезона, усложненная номинация, November 10, Problem I