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;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
constexpr long long INF = 1001001001001001LL;
constexpr long long MOD = 1000000007LL;
long long int N, h[100010];
signed main() {
  cin >> N;
  for (long long int(i) = (0); (i) < (N); (i)++) cin >> h[i];
  long long int ans = 0;
  stack<pair<long long int, long long int> > S;
  for (long long int(i) = (0); (i) < (N); (i)++) {
    if (S.empty()) S.push(pair<long long int, long long int>(h[i], i));
    pair<long long int, long long int> temp = S.top();
    if (temp.first < h[i])
      S.push(pair<long long int, long long int>(h[i], i));
    else if (temp.first > h[i]) {
      long long int lastpos = 0;
      while (!S.empty() && S.top().first >= h[i]) {
        lastpos = S.top().second;
        chmax(ans, S.top().first * (i - lastpos));
        S.pop();
      }
      S.push(pair<long long int, long long int>(h[i], lastpos));
    }
  }
  cout << ans << endl;
  return 0;
}
