~/algor $ cat problems/stack-gistogramma
Largest rectangle in a histogram
Medium
1000 ms
128 MB
62%
A histogram consists of $n$ columns standing side by side: each column has width $1$, and the height of the $i$-th is $h_{i}$. Find the area of the largest rectangle with sides parallel to the axes that fits inside the histogram (the rectangle must lie entirely within the columns).
Input
The first line contains a positive integer $n$. The second line contains $n$ positive integers $h_{i}$ separated by spaces.
Output
One integer — the largest area.
Note
$1 \le n \le 2 * 10^{5}$
$1 \le h_{i} \le 10^{9}$
Examples
Input #1
6 2 1 5 6 2 3
Output #1
10
Input #2
1 7
Output #2
7