Simple sum#9004

Simple sum

1 second
128 megabytes
Easy

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:

\sum_{l = 1}^n \sum_{r = l}^n \min(p_l, p_{l+1}, \ldots, p_r)

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.

Input

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.

Output

Print the required sum corresponding to the given sequence.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading