#P1823. [COI 2007] Patrik 音乐会的等待

[COI 2007] Patrik 音乐会的等待

Description

nn people are standing in a queue to enter a concert. People are bored, so they start turning around to look for their acquaintances in the line.

For any two people aa and bb in the queue, they can see each other if they are adjacent, or if there is no one between them who is taller than both aa and bb.

Write a program to compute how many pairs of people can see each other.

Input Format

The first line contains an integer nn, the number of people in the queue.

Each of the next nn lines contains an integer, the height of a person, in nanometers (equal to 10910^{-9} meters). These heights correspond to the people in the queue.

Output Format

Output a single line containing a number ss, the total number of pairs of people who can see each other.

7 
2 
4 
1 
2 
2 
5 
1
10

Hint

Constraints

For all test points, 11 \le each person’s height <231< 2^{31}, and 1n5×1051 \le n \le 5 \times 10^5.

Translated by ChatGPT 5