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 LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << ' '; clog << LF;}

struct Rect { int height, left; Rect(int h=0, int l=0): height(h), left(l) {} };

i64 slv(const int *bar, int W)
{
  stack<Rect> s;
  s.emplace(-1, -1);

  i64 largest = 0;
  for(int i = 0; i <= W; ++i) {
    const int h = bar[i];

    if(s.top().height < h) {
      s.emplace(h, i);
    }
    else if (s.top().height > h) {
      Rect r;
      while(s.top().height >= h) {
        r = s.top(); s.pop();
        chmax(largest, (i64)(i - r.left) * r.height);
      }
      s.emplace(h, r.left);
    }
  }

  return largest;
}

int N;
int a[100100];
signed main()
{
  cin >> N;
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  cout << slv(a, N) << endl;
  return 0;
}



