Codeforces Round 771 (Div. 2)
F
Two Posters
Codeforces
3200
原题
← E→
翻译中…

You want to advertise your new business, so you are going to place two posters on a billboard in the city center. The billboard consists of $n$ vertical panels of width $1$ and varying integer heights, held together by a horizontal bar. The $i$-th of the $n$ panels has height $h_i$.

翻译中…

image

翻译中…

Initially, all panels hang down from the bar (their top edges lie on it), but before placing the two posters, you are allowed to move each panel up by any integer length, as long as it is still connected to the bar (its bottom edge lies below or on it).

翻译中…

After the moves are done, you will place two posters: one below the bar and one above it. They are not allowed to go over the bar and they must be positioned completely inside of the panels.

翻译中…

What is the maximum total area the two posters can cover together if you make the optimal moves? Note that you can also place a poster of $0$ area. This case is equivalent to placing a single poster.

翻译中…

Input

翻译中…

The first line of input contains one integer $n$ ($1 \le n \le 10^4$) — the number of vertical panels.

翻译中…

The second line of input contains $n$ integers $h_1, h_2, ..., h_n$ ($1 \le h_i \le 10^{12}$) — the heights of the $n$ vertical panels.

翻译中…

Output

翻译中…

Print a single integer — the maximum total area the two posters can cover together.

翻译中…

Note

翻译中…

In the first sample test, we can choose an upper poster with area $12$ and a lower poster of area $6$ as in the image below.

翻译中…

image

翻译中…

In the second sample test, we can cover the whole billboard using a single poster.

翻译中…

样例

Input #1
6
2 2 3 5 4 5
Output #1
18
InputCopy OutputCopy
Input #2
1
1
Output #2
1
InputCopy OutputCopy
题目信息
题号
1638F
时间限制
2 s
内存限制
1024 MB
标签
暴力
数据结构
贪心
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。