eolymp
bolt
Try our new interface for solving problems
Problems

Balanced Photo

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 Li and Ri differ by more than factor of 2, where Li and Ri are the number of cows taller than i on her left and right, respectively. That is, i is unbalanced if the larger of Li and Ri 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 (1n105). The next n lines contain h1 .. hn, each a nonnegative integer at most 109.

Output

Print a count of the number of cows that are unbalanced.

Explanation

In this example, the cows of heights 34, 5 and 2 are unbalanced.

Time limit 1 second
Memory limit 128 MiB
Input example #1
7
34
6
23
0
5
99
2
Output example #1
3
Source 2017 USACO january, Gold