#K35297. Largest Rectangle in Histogram

    ID: 25500 Type: Default 1000ms 256MiB

Largest Rectangle in Histogram

Largest Rectangle in Histogram

You are given a histogram consisting of n bars, where the width of each bar is 1 and the height of the ith bar is given by h[i]. Your task is to determine the area of the largest rectangle that can be formed within the bounds of the histogram.

The area of a rectangle confined between bars i and j (inclusive) is computed as:

\( \text{Area} = (j - i + 1) \times \min_{i \leq k \leq j}(h[k]) \)

Write a program that reads the histogram data from standard input and prints the maximum possible rectangular area to standard output.

inputFormat

The first line of input contains a single integer n indicating the number of bars in the histogram. The second line contains n space-separated integers representing the heights of the bars.

outputFormat

Output a single integer, the maximum rectangular area that can be obtained in the histogram.

## sample
7
6 2 5 4 5 1 6
12