Given an array of length . The cost of a subarray is the product of the subarray's length and the sum of its two smallest numbers.
A subarray is a part of array , considering only the numbers at positions from to inclusive.
For example, let the array be [5, 3, 1, 5, 3]. Consider the subarray , with elements () — [3, 1, 5]. Its length is , the first minimum is , the second minimum is . Therefore, its cost is 3 \cdot (1 + 3) = 12. Consider another subarray , with elements () — . Its length is , the first minimum is , the second minimum is . Therefore, its cost is 2 \cdot (3 + 5) = 16.
Note that if the minimum number occurs more than once, it is still counted multiple times. For example, if there is a subarray [3, 1, 1], then its length is , the first minimum is , the second minimum is . So its cost is 3 \cdot (1 + 1) = 6.
Your task is to find the maximum cost among all subarrays of length at least two elements. That is, you need to find the maximum cost among all subarrays , where 1 \le l < r \le n.
The first line contains one integer (2 \le n \le 10^6).
The second line contains integers a_1, a_2, \dots, a_n (1 \le a_i \le 10^9).
Print one integer — the answer to the problem.
Example 1
Example 2
Example 3
In the first example, the maximum is achieved on the subarray , its length is , the minimums are and , the product is (1+3) \cdot 5 = 20.
In the second example, the maximum is achieved on the subarray , its length is , the minimums are and , the product is (10+77) \cdot 2=174.
In the third example, the maximum is achieved on the subarray , its length is , the minimums are and , the product is (2+3) \cdot 2=10.
points: 2 \le n \le 800
points: 2 \le n \le 5\,000
points: 2 \le n \le 20\,000
points: All tests are generated randomly as follows: first the number is determined (not randomly), then for each a_i where 1 \le i \le n, a value from to 10^9 inclusive is assigned with equal probability for each value. 2 \le n \le 10^5.
points: 2 \le a_i \le \sqrt{n}
points: No additional constraints