Little Marko is bored of playing with shady cryptocurrencies such as Shiba Inu or XRC,
which is why he decided to play with magnets. He has
Marko doesn't like it when the magnets attract each other, so he is interested in the number of ways
to place the magnets on the board so that no magnet attracts any other. All of the magnets should be
placed on the board, and each empty slot may contain at most one magnet. Two ways of placing the
magnets are considered different if there is a magnet which is at a different position in the first way than in the second way. As the required number can be quite large, you should output it modulo
Input Specification
The first line contains positive integers
The second line contains
Output Specification
Print the required number of ways to place the magnets on the board so that no magnet attracts any
other, modulo
Constraints
In every subtask, it holds that
Subtask | Points | Constraints |
---|---|---|
1 | 10 | |
2 | 20 | |
3 | 30 | |
4 | 50 | No additional constraints. |
Sample Input 1
1 10
10
Sample Output 1
10
Sample Input 2
4 4
1 1 1 1
Sample Output 2
24
Explanation for Sample Output 2
All permutations of the magnets are valid because no two magnets can attract each other.
Sample Input 3
3 4
1 2 1
Sample Output 3
4
Explanation for Sample Output 3
If we denote the magnets with 1
, 2
and 3
, and an empty slot with _
, the possible arrangements of magnets
are 13_2
, 31_2
, 2_13
and 2_31
.
Comments