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
# -*- coding: utf-8 -*-
"""
Pattern - Largest Rectangle in a Histogram
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C&lang=jp

"""
import sys


def solve(heights):
    h_len = len(heights)
    left = [-1] * h_len
    right = [-1] * h_len
    stack = []
    for i in range(h_len):
        if not stack:
            left[i] = 0
        else:
            while stack and stack[-1][1] >= heights[i]:
                stack.pop()
            left[i] = stack[-1][0]+1 if stack else 0
        stack.append((i, heights[i]))

    stack = []
    for i in range(h_len-1, -1, -1):
        if not stack:
            right[i] = h_len
        else:
            while stack and stack[-1][1] >= heights[i]:
                stack.pop()
            right[i] = stack[-1][0] if stack else h_len
        stack.append((i, heights[i]))

    area = [h*(r-l) for h, l, r in zip(heights, left, right)]
    return max(area)


def main(args):
    _ = input()
    heights = [int(h) for h in input().split()]
    ans = solve(heights)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

