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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
#include <stack>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;



int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> h(n); REP(i,n) cin >> h[i];

    vector<int> L(n), R(n); // L index, R index
    stack<int> st; // index
    for(int i=0; i < n; ++i) {
        while(st.size() && h[st.top()] >= h[i]) st.pop();
        L[i] = st.size() == 0 ? 0 : (st.top() + 1);
        st.push(i);
    }

    while(st.size()) st.pop();
    for(int i=n-1; i >= 0; --i) {
        while(st.size() && h[st.top()] >= h[i]) st.pop();
        R[i] = st.size() == 0 ? n : st.top();
        st.push(i);
    }


    long long res = 0;
    for(int i=0; i < n; ++i)
        res = max(res, 1LL * h[i] * (R[i] - L[i]));

    cout << res << endl;
    
    return 0;
}
