#t92. 最大存水量

最大存水量

Maximum Water Storage

Problem Description

You are given nn non-negative integers a1,a2,…,ana_1, a_2, \dots, a_n. Each integer represents a point (i,ai)(i, a_i) in the Cartesian plane.

We can now draw nn vertical line segments, where the ii-th segment has endpoints (i,ai)(i, a_i) and (i,0)(i, 0).

Among these nn segments, find two that, together with the xx-axis, form the sides of a container such that the container can hold the maximum amount of water. Note that you may not tilt the container.

Input Format

A non-negative integer n (1<n≤105)n\ (1 < n \le 10^5), followed by the nn integers in succession.

Output Format

The maximum amount of water the container can hold, as an integer (not exceeding 101810^{18}).

Sample Input 1

9
1 8 6 2 5 4 8 3 7

Sample Output 1

49

Sample Input 2

2
1 1

Sample Output 2

1

Sample Input 3

5
4 3 2 1 4

Sample Output 3

16

Sample Input 4

3
1 2 1

Sample Output 4

2

Hint

illustration

Explanation: the vertical lines in the figure represent the input array [1,8,6,2,5,4,8,3,7][1, 8, 6, 2, 5, 4, 8, 3, 7]. In this case, the maximum amount of water the container can hold (shown as the blue region) is 4949.