Difficulties
You are lining up n problems for a contest. Each problem has one of k difficulty labels. There are ai problems with label i, and a1+a2+⋯+ak=n.
Problems with the same label are indistinguishable. Problems with different labels are distinct. Count the number of distinct ordered problemsets (sequences of length n). Since the answer can be large, output it modulo 109+7.
Input
The first line contains two integers n and k.
The second line contains k integers a1,a2,…,ak.
It is guaranteed that a1+a2+⋯+ak=n.
Output
Print one integer: the number of distinct ordered problemsets, modulo 109+7.
Constraints
- 1≤k≤n≤106
- 0≤ai≤n
- a1+a2+⋯+ak=n
Example 1
3 2
2 1
3
Explanation
Write A for label 1 and B for label 2. The distinct sequences are AAB, ABA, and BAA.
Example 2
4 4
1 1 1 1
24
Explanation
Every problem has a distinct label, so every permutation of the 4 problems is distinct: 4!=24.
Example 3
6 3
3 2 1
60
Explanation
If the labels were all distinct there would be 6! sequences. The three copies of the first label are indistinguishable, as are the two copies of the second, so divide by 3!2!1!6!=60.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.