Balanced Photo
Farmer John is arranging his n cows in a line to take a photo. The height of the ith cow in sequence is hi, and the heights of all cows are distinct.
As with all photographs of his cows, FJ wants this one to come out looking as nice as possible. He decides that cow i looks "unbalanced" if L[i]
and R[i]
differ by more than factor of 2, where L[i]
and R[i]
are the number of cows taller than i on her left and right, respectively. That is, i is unbalanced if the larger of L[i]
and R[i]
is strictly more than twice the smaller of these two numbers. FJ is hoping that not too many of his cows are unbalanced.
Please help FJ compute the total number of unbalanced cows.
Input
The first line contains n (1 ≤ n ≤ 10^5
). The next n lines contain h[1]
.. h[n]
, each a nonnegative integer at most 10^9
.
Output
Print a count of the number of cows that are unbalanced.
Examples
Note
In this example, the cows of heights 34, 5 and 2 are unbalanced.