Dominating Duos

아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

A group of people are standing in a line. Each person has a distinct height. You would like to count the number of unordered pairs of people in the line such that they are taller than everyone in between them in the line.

More formally, let dd be a sequence of the heights of the people in order from left to right. We want to count the number of pairs of indices ii and jj with i<ji < j such that for all kk with i<k<ji < k < j, d_i>d_kd\_i > d\_k and d_j>d_kd\_j > d\_k. Note that if j=i+1j = i + 1 (i.e., there are no kk’s between ii and jj), it is trivially true.

입력

The first line of input contains an integer nn (2n1062 \le n \le 10^6), which is the number of people.

Each of the next n lines contains a single integer d_id\_i (1d_in1 \le d\_i \le n). These are the heights of the people in the group, in the order in which they’re standing. The sequence is guaranteed to be a permutation of the integers 11 through nn.

출력

Output a single integer, which is the number of pairs of people who are taller than everyone between them.