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
// AOJ DPL_3_C Largest Rectangle in a Histogram
// 2018.5.12 bal4u
 
#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

typedef struct { int lp, h; } STACK;
STACK *stack; int top;

long long maxRectInHistogram(int n, int *h)
{
	int i;
	long long s, ans;
	
	stack = malloc(sizeof(STACK) * (n+5));
	h[n] = 0;
	ans = 0, top = -1;
	stack[top].lp = -1, stack[++top].h = -1;
	for (i = 0; i <= n; i++) {
		if (h[i] == stack[top].h) continue;
		if (h[i] > stack[top].h) {
			stack[++top].lp = i, stack[top].h = h[i];
		} else {
			while (h[i] < stack[top].h) {
				s = (long long)stack[top].h*(i-stack[top].lp);
				top--;
				if (s > ans) ans = s;
			}
			stack[++top].h = h[i];
		}
	}
	free(stack);
	return ans;
}

int h[100002];

int main()
{
	int N, i;
	long long ans;

	N = in();
	for (i = 0; i < N; i++) h[i] = in();

	printf("%lld\n", maxRectInHistogram(N, h));
	return 0;
}

