#P3608. [USACO17JAN] Balanced Photo G
[USACO17JAN] Balanced Photo G
Description
Farmer John is arranging his cows in a line to take a photo (). The height of the th cow in sequence is , 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 looks "unbalanced" if and differ by more than factor of 2, where and are the number of cows taller than on her left and right, respectively. That is, is unbalanced if the larger of and 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 Format
The first line of input contains . The next lines contain , each a nonnegative integer at most 1,000,000,000.
Output Format
Please output a count of the number of cows that are unbalanced.
7
34
6
23
0
5
99
2
3
京公网安备 11011102002149号