#C10680. Maximum Water Container

    ID: 39912 Type: Default 1000ms 256MiB

Maximum Water Container

Maximum Water Container

Given a list of positive integers representing the heights of buildings, your task is to find the maximum area of water that can be trapped between any two buildings. The water container is formed by two buildings and the area is determined by the formula: $$Area = \min(h_i, h_j) \times (j - i)$$ where (h_i) and (h_j) are the heights of the two buildings and (j - i) is the distance between them.

Note: If there are less than two buildings, no container can be formed, so the maximum area is zero.

inputFormat

Input is read from standard input (stdin). The first line contains an integer (n) which denotes the number of buildings. The second line contains (n) space-separated positive integers representing the heights of the buildings.

outputFormat

Output a single integer to the standard output (stdout) which represents the maximum area of water that can be trapped between any two buildings.## sample

9
1 8 6 2 5 4 8 3 7
49