Time limit: 0.13s
Memory limit: 64MB
Input:
Output:
Given an array of elements from the set , a subarray is called linear if the equality is true, where and represent the number of elements equal to in the subarray and the number of elements equal to in the subarray, respectively, and and are given natural numbers.
Task
Determine the number of linear subarrays in the array .
Input data
The first line contains , , and separated by a space. The next line contains natural numbers, separated by a space, representing the elements of the array .
Output data
The first line will contain a natural number, representing the number of linear subarrays in the array .
Constraints and clarifications
# | Points | Constraints |
---|---|---|
0 | 0 | Examples |
1 | 11 | |
2 | 13 | |
3 | 17 | All values in the array are equal to |
4 | 59 | No additional constraints |
Example 1
stdin
9 1 3
1 0 1 1 1 0 0 1 1
stdout
4
Explanation
The linear subarrays are , , , and .
Example 2
stdin
9 3 8
1 1 1 0 1 0 0 0 1
stdout
4
Explanation
The linear subarrays are , , , and .
Example 3
stdin
5 2 5
1 0 0 1 1
stdout
0
Explanation
There are no linear subarrays.