atcoder#ABC247H. [ABC247Ex] Rearranging Problem
[ABC247Ex] Rearranging Problem
Score : points
Problem Statement
There are people called Person , Person , , Person , lined up in a row in the order of from the front. Person is wearing Color . Takahashi repeated the following operation times: choose two People and arbitrarily and swap the positions of Person and Person . After the operations have ended, the color that the -th person from the front is wearing coincided with , for every integer such that . How many possible permutations of people after the operations are there? Find the count modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4 1
1 1 2 1
3
Here is a comprehensive list of possible Takahashi's operations and permutations of people after each operation.
- Swap the positions of Person and Person , resulting in a permutation .
- Swap the positions of Person and Person , resulting in a permutation .
- Swap the positions of Person and Person , resulting in a permutation .
3 3
1 1 2
1
Here is an example of a possible sequence of Takahashi's operations.
- In the -st operation, he swaps the positions of Person and Person , resulting in a permutation . In the -nd operation, he swaps the positions of Person and Person , resulting in a permutation . In the -rd operation, he swaps the positions of Person and Person , resulting in a permutation .
Note that, during the sequence of operations, the color that the -th person from the front is wearing does not necessarily coincide with .
10 4
2 7 1 8 2 8 1 8 2 8
132