Chef found an array
ofelements. He defines a subarray as bad if the maximum element of the subarray is equal to the minimum element of the subarray.
More formally, a subarray
is bad if.
Chef is allowed to change at most
elements of the array.Find the minimum number of bad subarrays Chef can obtain after changing at most
elements of the array.
Input Format
- First line will contain
- - the initial array.
Output Format
For each test case, output the minimum number of bad subarrays Chef can obtain after changing at most
elements of the array.
Constraints
- .
Sample Input 1
3
3 1
1 2 3
4 2
3 3 3 1
5 1
1 1 1 1 1
Sample Output 1
3
4
7
Explanation
Test case
: The minimum number of bad subarrays Chef can obtain is . Chef does not need to perform any operations. The subarrays where the maximum element is equal to the minimum element are and where denotes the subarray starting at index and ending at index.
Test case
: The minimum number of bad subarrays Chef can obtain is . Chef can perform operations and change the array to . The subarrays where the maximum element is equal to the minimum element are and .
ConversionConversion EmoticonEmoticon