You are given an array of positive integers . Find the number of subarrays that have a majority element.
A subarray of length has a majority element if some number appears strictly greater than times in the subarray.
Constraints
for all .
Subtask 1 [5%]
Subtask 2 [10%]
Subtask 3 [15%]
Subtask 4 [20%]
Subtask 5 [25%]
Subtask 6 [25%]
Input Specification
The first line of input contains one integer: .
The second line of input contains space-separated integers. The th of these integers is .
Output Specification
Output one number: the number of subarrays that have a majority element.
Sample Input 1
4
1 2 1 3
Sample Output 1
5
Explanation for Sample Output 1
All single-element subarrays have a majority element, and the subarray also has a majority element.
Sample Input 2
10
1 3 2 3 1 3 3 2 2 4
Sample Output 2
25
Comments