#abc159f. [abc159_f]Knapsack for All Segments
[abc159_f]Knapsack for All Segments
Problem Statement
Given are a sequence of integers , , , and a positive integer .
For a pair of integers such that , let us define as follows:
- is the number of sequences of integers such that and .
Find the sum of over all pairs of integers such that . Since this sum can be enormous, print it modulo .
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 4
2 2 4
Sample Output 1
5
The value of for each pair is as follows, for a total of .
- (for the sequence )
- (for and )
- (for )
- (for )
Sample Input 2
5 8
9 9 9 9 9
Sample Output 2
0
Sample Input 3
10 10
3 1 4 1 5 9 2 6 5 3
Sample Output 3
152