PermutatioN#12853

PermutatioN

1 second
256 megabytes
Very hard

For a permutation of the numbers from to , define as follows: for every pair with 1 \le i \le j \le n, consider the pair , where is the smallest of the numbers p_i, p_{i+1}, \ldots, p_j and is the largest of them. Then equals the number of distinct pairs among all \frac{n(n+1)}{2} pairs.

For example, consider the permutation (1, 3, 2).

There are distinct pairs in total, so f((1, 3, 2)) = 5.

Find for the given permutation (p_1, p_2, \ldots, p_n).

Input

The first line contains one integer (1 \le n \le 2\cdot 10^5).

The second line contains integers p_1, p_2, \ldots, p_n (1 \le p_i \le n, all p_i are pairwise distinct) — the permutation of length .

Output

Print .

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading

Note

The first sample is explained in the statement.