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;

int main() {
	int n;
	cin >> n;
	vector<int64_t> h(n);
	for (auto &i : h) {
		cin >> i;
	}
	h.emplace_back(0);
	int64_t ans = 0;
	stack<pair<int64_t, int>> st;
	for (int i = 0; i <= n; i++) {
		if (st.empty() || st.top().first < h[i]) {
			st.emplace(make_pair(h[i], i));
		} else {
			if (h[i] < st.top().first) {
				int target = i;
				while (!st.empty() && h[i] <= st.top().first) {
					int64_t height = st.top().first;
					int pos = st.top().second;
					st.pop();
					int64_t area = height * (i - pos);
					ans = max(ans, area);
					target = pos;
				}
				st.emplace(make_pair(h[i], target));
			}
		}
	}
	cout << ans << endl;
	return 0;
}