#FT0000072. Những con số trong vụ án (Its a Murder!)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những con số trong vụ án (Its a Murder!)
Its a Murder!
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Detective Saikat walks up a staircase to reach a crime scene. Each step bears an integer, and he reads the numbers in the order he encounters them.
When he reads value on step , he writes in his notebook the sum of the values on all earlier steps that are strictly smaller than . If there are no such values, he writes . Earlier values equal to are not included.
Finally, he adds all the recorded amounts. Compute this total. The sum concerns the values, not merely the number of qualifying earlier steps.
Input
The first line contains the number of steps .
The second line contains integers in traversal order.
Output
Print one integer: the sum of all amounts written in Saikat’s notebook.
Subtasks
-
Subtask 1 (20 points): ; for every .
-
Subtask 2 (30 points): ; for every .
-
Subtask 3 (50 points): ; for every .
Examples
Input
5
1 5 3 6 4
Output
15
Explanation
For , the five notebook entries are:
- On , nothing is earlier: .
- On , only is smaller: .
- On , only is smaller: .
- On , values are smaller: .
- On , values are smaller: .
Their sum is , so print 15.