Circus 2
View as PDFLong before he became a goat, Andy was pursuing a career in academia. After writing that 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 posts in a line, where the
th post has height
. 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
and
is
.
If Andy chooses posts and
, the audience's excitement factor is
. Find the maximum possible excitement factor.
Input
The first line contains an integer , the number of posts.
The second line contains integers
, where
is the height of the
th post.
Output
Print a single integer: the maximum excitement factor Andy can achieve.
Constraints
Example 1
Input
5
1 2 3 4 5
Output
6
Explanation
Choosing the rd and
th posts gives excitement factor
.
Comments