100 atcoder#AGC008E. [AGC008E] Next or Nextnext
[AGC008E] Next or Nextnext
Score : points
Problem Statement
You are given an integer sequence of length . How many permutations of the integers through satisfy the following condition?
- For each , at least one of the following holds: and .
Find the count modulo .
Constraints
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the number of the permutations that satisfy the condition, modulo .
3
1 2 3
4
The following four permutations satisfy the condition:
For example, satisfies the condition because , and .
2
1 1
1
The following one permutation satisfies the condition:
3
2 1 1
2
The following two permutations satisfy the condition:
3
1 1 1
0
13
2 1 4 3 6 7 5 9 10 8 8 9 11
6