Subarray Search

View as PDF

Submit solution

Points: 7
Time limit: 0.5s
Memory limit: 256M

Author:
Problem type

Bob is playing with an array of N integers named a. Bob calls a subarray of a good if the maximum frequency of a number does not exceed F. Bob also calls a subarray great if the sum of the numbers in the subarray does not exceed S. 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 109+7.

Note: An empty subarray is not acceptable.

Constraints

1N105
1ai105 for all 1iN
1FN
1S1012

Subtask 1 [10%]

1N50

Subtask 2 [20%]

1N103

Subtask 3 [70%]

No additional constraints.

Input Specification

The first line of input will contain 3 integers N, F, and S, all separated by a single space.
The next line of input will contain N integers each separated by a space, which is the array a.

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 109+7.

Sample Input 1

Copy
3 2 4
1 2 3

Sample Output 1

Copy
96

Sample Input 2

Copy
10 3 10
2 3 5 2 2 3 4 1 4 1

Sample Output 2

Copy
46255

Comments

There are no comments at the moment.