Subarray Cost
문제
Given an array of length , a subarray is defined as the part of the array that includes only the elements located at positions from to inclusively. The cost of a subarray is defined as the product of the length of the subarray and the sum of its two smallest elements.
For example, let the array be . Let us consider the subarray . Its length is , its smallest element is , and its second smallest element is . Therefore, its cost is . Let us consider another subarray, . Its length is , its smallest element is , and its second smallest element is . Therefore, its cost is .
Note that if the minimal value occurs more than once in a subarray, it is counted several times. For example, the length of the subarray is , its smallest element is , and its second smallest element is also . Therefore, its cost is .
Given an array, find the maximum cost over all subarrays of at least two elements. That is, you need to find the maximum cost over all subarrays , where .
입력
The first line contains (), the length of the array. The second line contains integers ().
출력
Output a single integer, the maximum cost over all subarrays of at least two elements.
예제
예제 1
5 5 1 3 5 3
20
예제 2
7 1 1 3 5 10 77 5
174
예제 3
3 1 2 3
10