Score : 900 points
You are given a sequence of N integers: A_1,A_2,...,A_N.
Find the number of permutations p_1,p_2,...,p_N of 1,2,...,N that can be changed to A_1,A_2,...,A_N by performing the following operation some number of times (possibly zero), modulo 998244353:
Input is given from Standard Input in the following format:
N A_1 : A_N
Print the number of the sequences that satisfy the condition, modulo 998244353.
3 1 2 1
2
(2,3,1) and (3,2,1) satisfy the condition.
5 3 1 4 1 5
0
8 4 4 4 1 1 1 2 2
24
6 1 1 6 2 2 2
0