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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n; scanf("%lld", &n);
	vector<ll> h(n); for (ll i = 0; i < n; i++) scanf("%lld", &h[i]);
	stack<pair<int, int>> st;
	vector<ll> left(n);
	for (ll i = 0; i < n; i++) {
		ll cnt = 1;
		while (!st.empty() && st.top().first >= h[i]) {
			cnt += st.top().second;
			st.pop();
		}
		left[i] = cnt;
		st.emplace(h[i], cnt);
	}
	while (!st.empty()) st.pop();
	vector<ll> right(n);
	for (ll i = n - 1; i >= 0; i--) {
		ll cnt = 1;
		while (!st.empty() && st.top().first >= h[i]) {
			cnt += st.top().second;
			st.pop();
		}
		right[i] = cnt;
		st.emplace(h[i], cnt);
	}
	ll res = 0;
	for (ll i = 0; i < n; i++) {
		ll cnt = left[i] + right[i] - 1;
		chmax(res, h[i] * cnt);
	}
	
	cout << res << endl;
	return 0;
}

