Codeforces Round 771 (Div. 2) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

brute force

data structures

greedy

two pointers

*3200

No tag edit access

The problem statement has recently been changed. View the changes.

×
F. Two Posters

time limit per test

2 secondsmemory limit per test

1024 megabytesinput

standard inputoutput

standard outputYou 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$$$.

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.

Examples

Input

6 2 2 3 5 4 5

Output

18

Input

1 1

Output

1

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.

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

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/23/2024 07:58:07 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|