A histogram is made of a number of contiguous bars, which have same width.

For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.

Constraints

* $1 \leq N \leq 10^5$
* $0 \leq h_i \leq 10^9$

Input

The input is given in the following format.

$N$
$h_1$ $h_2$ ... $h_N$

Output

Print the area of the largest rectangle.

Examples

Input

8
2 1 3 5 3 4 2 1


Output

12


Input

3
2 0 1


Output

2
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
ll maxRectangleInHistogram(vector<int> &v) {
    int n = v.size();
    stack<int> s;
    vector<int> L(n), R(n);
    rep(i, 0, n) {
        while (s.size() && v[s.top()] >= v[i]) s.pop();
        L[i] = s.size() ? (s.top() + 1) : 0;
        s.push(i);
    }
    while (s.size()) s.pop();
    rrep(i, n - 1, 0) {
        while (s.size() > 0 && v[s.top()] >= v[i]) s.pop();
        R[i] = s.size() ? s.top() : n;
        s.push(i);
    }
    ll res = 0;
    rep(i, 0, n) res = max(res, 1LL * v[i] * (R[i] - L[i]));
    return res;
}
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/










int N, H[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N; rep(i, 0, N) cin >> H[i];

    vector<int> v(H, H + N);
    cout << maxRectangleInHistogram(v) << endl;
}