#FT0000068. Bức ảnh bò cân đối (Balanced Photo)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bức ảnh bò cân đối (Balanced Photo)
Balanced Photo
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Farmer John lines up cows for a photograph. Cow has height , and all heights are distinct.
For each cow, let be the number of taller cows to its left, and the number of taller cows to its right. A cow is unbalanced if the larger of is strictly greater than twice the smaller. This includes the case where one side has no taller cows but the other side has at least one.
Count the unbalanced cows in the photograph.
Input
The first line contains .
Next come integers in left-to-right order; the heights may be given one per line.
Output
Print one integer: the number of unbalanced cows.
Subtasks
-
Subtask 1 (20 points): ; for all cows; all heights are pairwise distinct.
-
Subtask 2 (30 points): ; for all cows; all heights are pairwise distinct.
-
Subtask 3 (50 points): ; for all cows; all heights are pairwise distinct.
Examples
Input
7
34
6
23
0
5
99
2
Output
3
Explanation
The heights are . The three unbalanced cows are:
- Height : , (only height ), and .
- Height : (heights ), (height ), so .
- Height : (heights ), .
The other four cows fail the strict inequality. Therefore the answer is 3.