As Rares failed his OOP exam mentioned earlier, he tries his luck with this problem hoping to forget his problems. We call an interesting-substring any substring which has at least one minimum value in its second half. is an interesting substring because its minimum, lays in the second half, while is not an interesting substring as its minimum, lays in the first half.
If the substring is of odd length, the middle is considered to be a part of the first half
In this problem, we consider that a substring is a contiguous subset of indices .
Given an array of elements, calculate the number of interesting substrings.
Input data
The first line contains a single number (). The second line contains positive numbers separated with spaces.
Output data
The only line contains the number of substrings computed.
Constraints and clarifications
- For points ;
- For another points, ;
- For the last points, .
Example 1
stdin
5
1 3 2 0 5
stdout
6
Example 2
stdin
6
0 0 2 3 1 0
stdout
8
Explanation
For the first example the substrings are: , , , , ,
For the second example the substrings are: , , , , , , ,