8461: Balanced Photo

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Farmer John is arranging his N cows in a line to take a photo (1N100,000). 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 ii looks "unbalanced" if Li and Ri differ by more than factor of 2, where Li and Rare the number of cows taller than ii on her left and right, respectively. That is, ii 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.

FJ正在安排他的N头奶牛站成一排来拍照。(1<=N<=100,000)序列中的第i头奶牛的高度是h[i],且序列中所有的奶牛的身高都不同。

就像他的所有牛的照片一样,FJ希望这张照片看上去尽可能好。他认为,如果L[i]和R[i]的数目相差1倍以上,第i头奶牛就是不平衡的(L[i]和R[i]分别代表第i头奶牛左右两边比她高的奶牛的数量)。也就是说,如果L[i]和R[i]中的较大数大于较小数的两倍,第i头奶牛就是不平衡的。FJ不希望他有太多的奶牛不平衡。

请帮助FJ计算不平衡的奶牛数量。

输入格式

第一行一个整数N。接下N行包括H[1]到H[n],每行一个非负整数(不大于1,000,000,000)。

输出格式

请输出不平衡的奶牛数量。

输入样例 复制

7
34
6
23
0
5
99
2

输出样例 复制

3