ThingExplainer is a well-known koala in the koala world for his excellent explanations. You tune into a recording of his most recent explanation about a game called Koala Ball.
In the game, there are
Wanting to show ThingExplainer his skills, Daniel the Koala asks you to help him find the number of ways to split all the balls among the baskets. The answer may be very large, and as Koalas are not very proficient mathematicians, he asks you to give him the answer modulo
Note: Two arrangements are considered different if any basket contains a different amount of a certain type of ball.
This problem was originally part of the An Animal Contest 2 problemset.
Constraints
Subtask 1 [10%]
Subtask 2 [90%]
No additional constraints.
Input Specification
The first line of input contains
The next line contains
Each of the next
Output Specification
Output a single integer, the number of ways, modulo
Sample Input 1
2 3 1
1 1
1 1 1 0
Sample Output 1
6
Sample Input 2
2 4 3
2 2
3 4 2 1
1 1 2 1
2 2 1 1
Sample Output 2
54
Comments