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 int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-6;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
const int64 mod = 1e9 + 7;
int32 H, W;
vector<int32> v;
vector<string> s;
int main(void) {
  cin >> W;
  v.resize(W);
  for (int i = 0; i < (W); i++) {
    cin >> v[i];
  }
  int64 res = 0;
  stack<PLL> st;
  st.push(PLL(-1, -1));
  for (int j = 0; j < (W - 1); j++) {
    while (st.top().first >= v[j]) st.pop();
    res = max(res, (v[j] + 1) * (j - st.top().second + 1));
    st.push(PLL(v[j], j));
  }
  cout << res << endl;
}
