#K53562. Largest Rectangle in Histogram

    ID: 29559 Type: Default 1000ms 256MiB

Largest Rectangle in Histogram

Largest Rectangle in Histogram

Given a histogram represented by n non-negative integers, where each integer corresponds to the height of a bar and each bar has a unit width, your task is to compute the area of the largest rectangle that can be formed within the bounds of the histogram.

The rectangle's area is calculated as \(area = height \times width\). In this context, the width is determined by the number of contiguous bars that can form a rectangle with at least the minimum height among them.

For instance, if the input histogram is [2, 1, 5, 6, 2, 3], the largest rectangular area is 10. Use efficient algorithms to handle larger inputs.

inputFormat

The first line contains an integer n, representing the number of bars in the histogram. The second line contains n space-separated integers, where each integer is the height of a bar.

outputFormat

Output a single integer which denotes the largest rectangular area that can be formed in the histogram.

## sample
6
2 1 5 6 2 3
10

</p>