문제
Farmer John's cows ( have heights . One day, the cows are standing in a line in some order playing frisbee; let denote the heights of the cows in this order (so the 's are a permutation of ).
Two cows at positions and in the line can successfully throw the frisbee back and forth if and only if every cow between them has height lower than .
Please compute the sum of distances between all pairs of locations at which there resides a pair of cows that can successfully throw the frisbee back and forth. The distance between locations and is .
입력
The first line of input contains a single integer . The next line of input contains , separated by spaces.
출력
Output the sum of distances of all pairs of locations at which there are cows that can throw the frisbee back and forth. Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
예제 입력 1
7
4 3 1 2 5 6 7
예제 출력 1
24
점수
Test cases 1-3 satisfy .Test cases 4-11 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인