atcoder#AGC043D. [AGC043D] Merge Triplets
[AGC043D] Merge Triplets
Score : points
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 .
- 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 .
1 998244353
6
All permutations of length count.
2 998244353
261
314 1000000007
182908545