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;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<lint> h(n + 2); for (int i = 0; i < n; i++) cin >> h[i + 1];
  V<lint> a = h;
  h[0] = h[n + 1] = -1;
  auto add = [&] {
    stack<int> s;
    s.push(0);
    for (int i = 1; i < n + 1; i++) {
      while (h[s.top()] >= h[i]) s.pop();
      a[i] += h[i] * (i - s.top() - 1);
      s.push(i);
    }
  };
  add();
  reverse(h.begin(), h.end());
  reverse(a.begin(), a.end());
  add();
  cout << *max_element(a.begin(), a.end()) << '\n';
}
