Nikhat arranged the numbers in ascending order. Later Hussein came and swapped some of these numbers. Now we have some mixed sequence of numbers from to .
Calculate the following sum for this sequence:
Simply put, you need to find the sum of all the minimum numbers in all subsequences of a given sequence.
The min
function finds the minimum of the given numbers.
The first line contains one integer - the number of numbers in the sequence. The second line contains integers - elements of the sequence.
Print the required amount corresponding to the given sequence.