Bob is playing with an array of integers named
. Bob calls a subarray of
good if the maximum frequency of a number does not exceed
. Bob also calls a subarray great if the sum of the numbers in the subarray does not exceed
. Finally, Bob calls an array great-good if it is both a good array and a great array. Bob wants you to find the number of great subarrays multiplied by the number of good subarrays multiplied by the number of great-good subarrays. Since this number can be quite large, output it modulo
.
Note: An empty subarray is not acceptable.
Constraints
for all
Subtask 1 [10%]
Subtask 2 [20%]
Subtask 3 [70%]
No additional constraints.
Input Specification
The first line of input will contain 3 integers ,
, and
, all separated by a single space.
The next line of input will contain integers each separated by a space, which is the array
.
Output Specification
Output 1 integer, the number of great subarrays multiplied by the number of good subarrays multiplied by the number of great-good subarrays modulo .
Sample Input 1
3 2 4
1 2 3
Sample Output 1
96
Sample Input 2
10 3 10
2 3 5 2 2 3 4 1 4 1
Sample Output 2
46255
Comments