Wholesome Kevin
Kevin has quite the reputation around ACPC: he is wholesome and brings happiness everywhere. Currently, he is building a rectangular water trough for cute stray animals in need.
He has a row of wooden planks standing upright on a 2D plane. The
-th plank from the left is located at
and has a height of
.
Kevin may choose two planks and
, where
, to form the walls of a trough. Normally, its capacity would be
. However, Kevin considers a trough wholesome only if neither wall extends above the water level. Therefore, the two chosen planks must have the same height:
.
For a valid pair of planks, the capacity is . Planks between the two chosen walls do not affect the capacity.
Find the maximum capacity of a wholesome trough Kevin can build. If no pair of planks has the same height, output .
Input
The first line contains an integer (
), the number of wooden planks.
The second line contains integers
(
), the heights of the planks from left to right.
Output
Output the maximum capacity of a wholesome trough. If no wholesome trough can be formed, output .
Examples
Input 1
5
3 1 4 3 4
Output 1
9
Kevin has two options for forming a wholesome trough:
- Choose planks
and
, which both have height
. The capacity is
.
- Choose planks
and
, which both have height
. The capacity is
.
Therefore, the maximum capacity is .
Input 2
4
1 2 3 4
Output 2
-1
All planks have different heights, so Kevin cannot build a wholesome trough.
Input 3
7
5 5 1 5 2 5 1
Output 3
25
Choosing the first and sixth planks produces a trough with capacity .
Comments