#d11002. 第二大数字和
第二大数字和
Sum of Second Largests
Problem Description
You are given a permutation of .
For a pair of indices (), let be the second largest value among .
Compute the following sum:
Input Format
The first line contains an integer .
The second line contains integers .
Output Format
Output one line containing a single integer: the value of .
Sample Input
5
1 2 3 4 5
Sample Output
30
Constraints
, , and for .
Hint
If you passed this problem in , try to think of a faster solution.