#P4709. 信息传递

信息传递

Description

Given a permutation

$$f = \begin{pmatrix} 1 & 2 & ... & n \\\ a_1 & a_2 & ... & a_n \end{pmatrix}$$

find how many permutations gg satisfy

gn=fg ^ n = f

Output the answer modulo 998244353998244353.

Input Format

The first line contains an integer nn.

The second line contains nn integers a1,a2,...,ana_1, a_2, ..., a_n.

Output Format

Output the answer.

3
2 1 3
1

Hint

Sample explanation:

There is only one permutation with a1=2,a2=1,a3=3a_1 = 2, a_2 = 1, a_3 = 3 that satisfies

$${\begin{pmatrix} 1 & 2 & 3 \\ 2 & 1 & 3 \end{pmatrix}} ^ 3 = \begin{pmatrix} 1 & 2 & 3 \\ 2 & 1 & 3 \end{pmatrix}$$

Constraints:

For 20%20\% of the testdata, n10n \le 10.

For 60%60\% of the testdata, n1000n \le 1000.

For 100%100\% of the testdata, n105n \le {10} ^ 5.

Translated by ChatGPT 5