#C9212. Confrontations in Insect Species
Confrontations in Insect Species
Confrontations in Insect Species
You are given a sequence of insect species represented by their strength levels. In this contest problem, a confrontation occurs when an insect is preceded by another insect with a greater strength level. More formally, for an insect with strength si (with i > 1), if there exists an index j (with 1 ≤ j < i) such that sj > si and sj is the maximum encountered among the first i-1 insects, then a confrontation is said to occur. Your task is to count the total number of confrontations in the sequence.
For example, consider the sequence \( [4,2,6,3,1] \). The confrontations occur when:
- The insect with strength 2 is preceded by 4.
- The insect with strength 3 is preceded by 6.
- The insect with strength 1 is preceded by 6.
So, the answer in this case is 3.
inputFormat
The first line of the input contains an integer \( n \) representing the number of insect species.
The second line contains \( n \) space-separated integers representing the strength levels of the insect species.
outputFormat
Print a single integer: the total number of confrontations that occur in the sequence.
## sample5
4 2 6 3 1
3
</p>