#K94807. Maximum Water Container

    ID: 38723 Type: Default 1000ms 256MiB

Maximum Water Container

Maximum Water Container

You are given N vertical lines on a coordinate plane where the i-th line has a height hi. These lines are positioned at coordinates 1, 2, ..., N along the x-axis. Your task is to find two lines that together with the x-axis form a container, such that the container contains the most water.

The area of water contained is determined by the distance between the two lines and the minimum of their heights. In mathematical terms, if the two lines are at positions i and j with i < j, then the area is given by:

$$A = (j - i) \times \min(h_i, h_j)$$

Implement an efficient algorithm to compute the maximum area possible.

inputFormat

The first line contains a positive integer N representing the number of vertical lines.
The second line contains N space-separated integers representing the heights of the lines.

Example:

9
1 8 6 2 5 4 8 3 7

outputFormat

Output a single integer representing the maximum water container area.

## sample
9
1 8 6 2 5 4 8 3 7
49