atcoder#TENKA12018F. Circular
Circular
Score : points
Problem Statement
You are given a sequence of integers: .
Find the number of permutations of that can be changed to by performing the following operation some number of times (possibly zero), modulo :
- For each , let , where . Replace the sequence with the sequence .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of the sequences that satisfy the condition, modulo .
3
1
2
1
2
and 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