Difficulties
View as PDFYou are lining up problems for a contest. Each problem has one of
difficulty labels.
There are
problems with label
, and
.
Problems with the same label are indistinguishable. Problems with different labels are distinct.
Count the number of distinct ordered problemsets (sequences of length ). Since the answer can
be large, output it modulo
.
Input
The first line contains two integers and
.
The second line contains integers
.
It is guaranteed that .
Output
Print one integer: the number of distinct ordered problemsets, modulo .
Constraints
Example 1
Input
3 2
2 1
Output
3
Explanation
Write for label
and
for label
. The distinct sequences are
,
, and
.
Example 2
Input
4 4
1 1 1 1
Output
24
Explanation
Every problem has a distinct label, so every permutation of the problems is distinct:
.
Example 3
Input
6 3
3 2 1
Output
60
Explanation
If the labels were all distinct there would be sequences. The three copies of the first
label are indistinguishable, as are the two copies of the second, so divide by
.
Comments