Expected Cycle Size

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

TL;DR Permutation pattern is a permutation with 0 as a wildcard. You are given a permutation pattern. For each index, find its expected cycle size if a random permutation conforming to the pattern is chosen and output it modulo 998,244,353998\\,244\\,353.

And now five times as long, three times as formal

A permutation is an array pp of length nn, such that _ij:p_ip_j,_i:1p_in\forall\_{i \neq j}: p\_i \neq p\_j, \forall\_i: 1 \leq p\_i \leq n

The product of permutations pp and qq which have the same length, denoted as pqp \cdot q is the permutation r of the same length as both pp and qq, such that _i:r_i=p_q_i\forall\_i: r\_i = p\_{q\_i}

The power pkp^k where pp is a permutation and kk is a positive integer is

  1. pp if kk = 1
  2. pk1pp^{k-1} \cdot p otherwise

Cycle size of index i is the minimal positive integer k, such that (pk)_i=i(p^k)\_i = i. It can be shown that such number always exists.

Permutation pattern is an array of length nn such that _ij:a_i=0ora_ia_j,_i:0a_in\forall\_{i \neq j}: a\_i = 0 or a\_i \neq a\_j, \forall\_i: 0 \leq a\_i \leq n.

We say permutation pp conforms to the pattern tt if _i:p_i=t_iort_i=0\forall\_i: p\_i = t\_i or t\_i = 0.

Let ans_ians\_i be the expected cycle size of index i in a random permutation conforming to the pattern given in input. You are to find ans_ians\_i modulo 998,244,353998\\,244\\,353.

Taking a potentially non-integer number XX modulo MM is the following procedure:

Jury guarantees that XX is equal to some irreducible fraction PQ\frac{P}{Q} where Q has an inverse modulo MM. In that case XX modulo M=AM = A, where AA is an integer between 0 and M1M - 1 inclusive and PQAP - QA is divisible by MM. It can be shown that AA is unique.

입력

The first line contains one integer nn (1n1061 \leq n \leq 10^6), the length of the permutation pattern.

The second line contains nn space separated integers t_it\_i (0t_in0 \leq t\_i \leq n).

It is guaranteed that tt is a permutation pattern.

출력

Output nn integers. ii-th of them must be equal to ans_ians\_i modulo 998,244,353998\\,244\\,353.

힌트

In the second example both ans_ians\_i are equal to 32\frac{3}{2} which equals 499122178 modulo 998244353.