#agc043d. [agc043_d]Merge Triplets
[agc043_d]Merge Triplets
Problem Statement
Given is a positive integer . Find the number of permutations of that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number .
- Make sequences of length each, using each of the integers through exactly once.
- Let be an empty sequence, and do the following operation times.
- Among the elements that are at the beginning of one of the sequences that is non-empty, let the smallest be .
- Remove from the sequence, and add at the end of .
Constraints
- is a prime number.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of permutations modulo .
Sample Input 1
1 998244353
Sample Output 1
6
All permutations of length count.
Sample Input 2
2 998244353
Sample Output 2
261
Sample Input 3
314 1000000007
Sample Output 3
182908545