#arc110d. [arc110_d]Binomial Coefficient is Fun
[arc110_d]Binomial Coefficient is Fun
Problem Statement
We have a sequence of non-negative integers.
Compute the sum of over all sequences of non-negative integers whose sum is at most , and print it modulo ().
Here, , the binomial coefficient, denotes the number of ways to choose objects from objects, and is when .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of , modulo .
Sample Input 1
3 5
1 2 1
Sample Output 1
8
There are four sequences such that is at least :
-
, where $\\prod _{i = 1} ^N \\dbinom{B_i}{A_i} = \\dbinom{1}{1} \\times \\dbinom{2}{2} \\times \\dbinom{1}{1} = 1$;
-
, where $\\prod _{i = 1} ^N \\dbinom{B_i}{A_i} = \\dbinom{2}{1} \\times \\dbinom{2}{2} \\times \\dbinom{1}{1} = 2$;
-
, where $\\prod _{i = 1} ^N \\dbinom{B_i}{A_i} = \\dbinom{1}{1} \\times \\dbinom{3}{2} \\times \\dbinom{1}{1} = 3$;
-
, where $\\prod _{i = 1} ^N \\dbinom{B_i}{A_i} = \\dbinom{1}{1} \\times \\dbinom{2}{2} \\times \\dbinom{2}{1} = 2$.
The sum of these is .
Sample Input 2
10 998244353
31 41 59 26 53 58 97 93 23 84
Sample Output 2
642612171