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;
#define FOR(i,s,t) for(int i = s; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl;
#define SZ(a) (int)a.size()
using LL = long long; template<class T> using V = vector <T>; template <class T> using VV = V<V<T>>;


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N; cin >> N;
	V<int>h(N);
	FOR(i, 0, N) {
		cin >> h[i];
	}
	// iに対するl,rを決定する
	V<int>st(N+1);
	int tpos = 0;
	V<LL>R(N + 1), L(N + 1);
	FOR(i, 0, N) {
		while (tpos && h[st[tpos - 1]] >= h[i]) {
			tpos--;
		}
		if (tpos) {
			L[i] = st[tpos - 1] + 1;
		}
		else {
			L[i] = 0;
		}
		st[tpos++] = i;
	}
	tpos = 0;
	for (int i = N - 1; i >= 0; i--){
		while (tpos && h[st[tpos - 1]] >= h[i]) {
			tpos--;
		}
		if (tpos) {
			R[i] = st[tpos - 1] ;
		}
		else {
			R[i] = N;
		}
		st[tpos++] = i;
	}
	LL ans = 0;
	FOR(i, 0, N) {
		ans = max(ans, h[i] * (R[i] - L[i]));
	}
	cout << ans << endl;


	return 0;
}
