Circus 2


Long before he became a goat, Andy was pursuing a career in academia. After writing that 1717 is a composite number on an exam, Andy decided that if he was going to be a clown anyway, he may as well join the circus. Andy is once again in charge of setting up the tightropes.

There are nn posts in a line, where the iith post has height aia_i. Andy must choose exactly two posts. The height of the tightrope is the minimum of the two chosen post heights, and the distance between posts ii and jj is ij|i - j|.

If Andy chooses posts ii and jj, the audience's excitement factor is ijmin(ai,aj)|i - j| \cdot \min(a_i, a_j). Find the maximum possible excitement factor.

Input

The first line contains an integer nn, the number of posts.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n, where aia_i is the height of the iith post.

Output

Print a single integer: the maximum excitement factor Andy can achieve.

Constraints

  • 2n21052 \le n \le 2 \cdot 10^5
  • 1ai1091 \le a_i \le 10^9

Example 1

Input 1
5
1 2 3 4 5
Output 1
6
Explanation

Choosing the 33rd and 55th posts gives excitement factor 53min(3,5)=23=6|5 - 3| \cdot \min(3, 5) = 2 \cdot 3 = 6.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.