All submissions for this problem are available.
Let’s define a value of a sequence as the difference between the largest and the smallest number within that sequence. For example, value of sequence (3, 1, 7, 2) is 6, and value of (42, 42) is 0.Find the sum of values of all subsequences of consecutive elements of a given sequence.
The first line of input contains a single integer N , number of elements of the sequence.Next N lines contain elements of the sequence. Each element is a positive integer not greater than 100 000 000.
The first and only line of output must contain the requested sum.
- 2 ≤ N ≤ 300000
Input: 3 1 2 3 Output: 4
Input: 4 7 5 7 5 Output: 12
Input: 4 3 1 7 2 Output: 31
|Time Limit:||0.1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, RUBY, PHP, GO, PERL, JS, PERL6, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.