#P13550. 宇宙分解
宇宙分解
Description
You are given a sequence and two operations:
- Choose and delete .
- Choose and swap these two numbers.
You must repeatedly perform these operations until no more operations can be done. How many distinct sequences can be obtained at the end?
Input Format
The first line contains an integer .
The second line contains integers, where the -th integer is .
Output Format
Output an integer representing the number of distinct sequences obtained at the end, modulo .
5
4 5 2 3 1
4
4
2 2 2 2
1
Hint
Sample Explanation
For Sample #1, there are four possible outcomes:
- : Obtained by performing two deletions to remove and .
- : Obtained by deleting and moving to the front.
- : Obtained by performing two swaps to sort the sequence.
- : Obtained by deleting and then sorting the sequence.
For Sample #2, no operations can be performed initially.
Constraints
| Test | Special Properties | ||
|---|---|---|---|
| None | |||
| All are distinct | |||
| None | |||
For all test cases, , .
Generated by Deepseek V3.
京公网安备 11011102002149号