Subarray Cost
시간 제한5초메모리 제한2048 MB
길이가 2 이상인 부분 배열 중에서 (길이) 곱하기 (가장 작은 두 원소의 합)을 최대로 만드는 값을 구한다.
문제
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.