~/algor $ cat problems/ikki-korsatkich-eng-katta-idish
Container with the most water
Medium
1000 ms
128 MB
49%
$n$ vertical walls stand in a row, the height of the $i$-th wall is $h_{i}$, the distance between neighbouring walls is $1$. Two walls $i \lt j$ are chosen and water is poured between them: the water level equals the height of the lower wall, and the walls in between do not get in the way. Then $(j - i) \cdot \min(h_{i}, h_{j})$ units of water fit. What is the largest number of units of water that can fit?
Input
The first line contains a positive integer $n$. The second line contains $n$ integers $h_{i}$ separated by spaces.
Output
One integer — the largest amount of water.
Note
$2 \le n \le 2 * 10^{5}$
$0 \le h_{i} \le 10^{9}$
Examples
Input #1
6 1 5 2 4 6 3
Output #1
15
Input #2
2 3 7
Output #2
3