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 INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

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<vector<int32>> v;
vector<string> s;

int main(void){
	cin >> H >> W;
	s.resize(H);
	v = vector<vector<int32>>(H-1, vector<int32>(W-1, 0));
	REP(i, H){
		cin >> s[i];
	}
	REP(i, H-1){
		REP(j, W-1){
			int32 cnt = 0;
			REP(k, 2){
				REP(l, 2){
					cnt += s[i+k][j+l] == '.';
				}
			}
			if(cnt%2 == 0) v[i][j] = 1;
		}
	}
	FOR(i, 1, H-1){
		REP(j, W-1){
			if(v[i][j] == 1) v[i][j] += v[i-1][j];
		}
	}
	int64 res = max(H, W);
	REP(i, H-1){
		stack<PLL> st;
		st.push(PLL(-1, -1));
		REP(j, W-1){
			while(st.top().fs >= v[i][j]) st.pop();
			res = max(res, (v[i][j]+1)*(j-st.top().sc+1));
			st.push(PLL(v[i][j], j));
		}
	}
	cout << res << endl;
}
*/

int main(void){
	int32 N;
	vector<int64> v;
	cin >> N;
	v.resize(N);
	REP(i, N) cin >> v[i];
	v.push_back(0);
	int64 res = 0;
	stack<PLL> st;
	st.push(PLL(-1, -1));
	REP(i, N+1){
		int32 l = i;
		while(st.top().fs >= v[i]){
			res = max(res, st.top().fs*(i-st.top().sc));
			l = st.top().sc;
			st.pop();
		}
		st.push(PLL(v[i], l));
	}
	cout << res << endl;
}
