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
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll n;
    cin >> n;
    ll a[n + 1];
    a[n] = -1;
    rep(i, n) cin >> a[i];

    stack<ll> st;
    ll max_area = 0;

    for (int i = 0; i <= n; i++)
    {
        while (!st.empty() && a[st.top()] > a[i])
        {
            int t = st.top();
            st.pop();
            max_area = max(max_area, a[t] * (st.empty() ? i : i - st.top() - 1));
        }
        st.push(i);
    }
    OP(max_area);

    return 0;
}
