Nikhat arranged the numbers 1, 2, \ldots, n in ascending order. Later Hussein came and swapped some of these numbers. Now we have some mixed sequence p_1, p_2, \ldots, p_n 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 subarrays of a given sequence.
The function finds the minimum of the given numbers.
The first line contains one integer (1 \le n \le 10^5) — the number of numbers in the sequence. The second line contains integers p_i (1 \le p_i \le n) — elements of the sequence.
Print the required sum corresponding to the given sequence.
Example 1
Example 2