0 atcoder#ABC140E. [ABC140E] Second Sum
[ABC140E] Second Sum
Score: points
Problem Statement
Given is a permutation of .
For a pair , let be the second largest value among .
Find $\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}$.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print $\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}$.
3
2 3 1
5
, and , so the sum is .
5
1 2 3 4 5
30
8
8 2 7 3 4 5 6 1
136