#abc351f. F - Double Sum
F - Double Sum
Score: points
问题陈述
给定一个整数序列 。 计算以下表达式:
$\displaystyle \sum_{i=1}^N \sum_{j=i+1}^N \max(A_j - A_i, 0)$
约束条件保证答案小于 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given an integer sequence .
Calculate the following expression:
$\displaystyle \sum_{i=1}^N \sum_{j=i+1}^N \max(A_j - A_i, 0)$
The constraints guarantee that the answer is less than .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the value of the expression.
Sample Input 1
3
2 5 3
Sample Output 1
4
For , we have .
For , we have .
For , we have .
Adding these together gives , which is the answer.
Sample Input 2
10
5 9 3 0 4 8 7 5 4 0
Sample Output 2
58