Y - Dominating Duos
题号:NC224693
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

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  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  and  with  such that for all  with , and . Note that if  (i.e., there are no ’s between  and ), it is trivially true.

输入描述:

The first line of input contains an integer , which is the number of people.
Each of the next  lines contains a single integer . 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 1 through .

输出描述:

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

输入

复制
3
2
1
3

输出

复制
3
示例2

输入

复制
6
1
3
2
6
4
5

输出

复制
7

备注: