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 <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> h(n),l(n),r(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &h[i]);
    }

    vector<int> v;
    for(i=0; i<n; i++) {
        while(!v.empty() && h[v.back()]>=h[i]) {
            v.pop_back();
        }
        l[i]=(v.empty()? 0: v.back()+1);
        v.push_back(i);
    }

    v.clear();
    for(i=n-1; i>=0; i--) {
        while(!v.empty() && h[v.back()]>=h[i]) {
            v.pop_back();
        }
        r[i]=(v.empty()? n-1: v.back()-1);
        v.push_back(i);
    }

    ll S=0;
    for(i=0; i<n; i++) {
        ll tmp=(ll)h[i]*(r[i]-l[i]+1);
        S=MAX(S,tmp);
    }
    printf("%lld\n", S);

    return 0;
}

