You are excavating what remains of a very old Indian temple. The architecture of the temple is very curious: you found a line of $$$N$$$ towers of different heights (no two towers have the same height), all spaced by one meter (the radius of each tower is supposed to be negligible).
During the excavations, you find something which might explain this curious architecture: the tomb of the architect. You find the following epitaph on the tomb:
To achieve perfection, visit each tower;
For each, compute the distance to the closest tower that is taller$$$^{\text{∗}}$$$;
Add every such distance.
If thou can follow this guidance,
Enlightened shalt thou be by this result,
And great in thy temple shall be the cult.
You wonder how to compute this sum, this "enlightenment score" of the temple.
You are given a positive integer $$$N$$$ corresponding to the number of towers, and an array $$$H$$$ of $$$N$$$ distinct non-negative integers corresponding to the heights of the towers. $$$H_0$$$ is the height of the leftmost tower, $$$H_1$$$ is the height of the tower to the right of $$$H_0$$$, and so on. Finally, $$$H_{N-1}$$$ is the height of the rightmost tower. Observe that the distance between any two towers, in meters, is the absolute value of the difference of their respective indices in the array $$$H$$$. Let $$$p$$$ denote the index of the tallest tower in $$$H$$$ and define, for every $$$i\neq p$$$, $$$$$$ d(i) =\min\{ |i-j|\mbox{: for every $j$ such that $H_j \gt H_i$\}.} $$$$$$ Note that $$$d(p)$$$ is not defined. The "enlightenment score" of the temple is then given by $$$$$$ \sum_{i=0 , i\neq p}^{N-1} d(i). $$$$$$
$$$^{\text{∗}}$$$The closest taller tower can be on the left or on the right. For the tallest tower, this distance is undefined and should not be considered in the final sum.
The first line contains the integer $$$N$$$. The second line contains the list of elements $$$H_0,\dots,H_{N-1}$$$ of the array $$$H$$$ of heights, separated by spaces.
The output should contain one line with the enlightenment score of the temple.
Limits
5 7 3 2 100 1
6
8 45 13 18 10 8 56 17 19
13
Sample Explanation 1
Sample Explanation 2
| Название |
|---|


