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>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans, s;
int main() {
    vl A,ANS(MAX_N);
    cin >> n;
    A.push_back(0);
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }
    A.push_back(0);
    n+=2;
    vl X(n,0),Y(n,0);

    deque<PP> DQ;

    rep(i, n) {
        while (!DQ.empty() && DQ.back().second > A[i]){
            X[DQ.back().first] += i - DQ.back().first;
            DQ.pop_back();
        }
        DQ.push_back({i, A[i]});
    }
    

    reverse(all(A));

    DQ.clear();

    rep(i, n) {
        while (!DQ.empty() && DQ.back().second > A[i]){
            Y[DQ.back().first] += i - DQ.back().first;
                    DQ.pop_back();
        }
        DQ.push_back({i, A[i]});
    }
    
	
    reverse(all(Y));
    reverse(all(A));

    rep(i, n) { ANS[i] = X[i] + Y[i]-1;
        ans = max(ans, ANS[i] * A[i]);
    }
    

    cout << ans << endl;
}
