시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB32231773.913%

## 문제

Your treasure hunter team has just discovered a giant archeological site, full of precious metals and valuable antiquities. The site is composed of $n$ digging spots on a line.

The initial plans suggest that each of the $n$ digging spots has a net profit associated with it. The $i$-th spot’s associated profit is $p_i$. More specifically, this means that your team would gain $p_i$ dollars for each meter dug in the $i$-th spot. Note that $p_i$ may also be negative, which means that the running cost of the excavating machinery surpasses the actual gain from digging in the $i$-th spot.

Naturally, you would want to dig as much as possible in the most profitable spots. However, in order not to cause landslides, you are not allowed to have slopes that are too steep. More precisely, for any two adjacent spots, the difference between the digging depth at these spots cannot differ by more than $1$ meter. In particular, spots $1$ and $n$ can be dug only at most $1$ meter deep.

What is the largest net profit that you can obtain, under these conditions?

For instance, a valid digging plan that turns out to be optimal in the case of the first example input is illustrated below. The net profit of such plan is $8$.

## 입력

The first line of the input will contain a positive integer $n$ ($1 \le n \le 250\,000$).

The second line of the input will contain $n$ integers $p_i$ ($-10^6 \le p_i \le 10^6$), separated by spaces.

## 출력

Output exactly one integer, the largest profit that you can obtain.

## 예제 입력 1

5
1 3 -4 2 1


## 예제 출력 1

8


## 예제 입력 2

4
1 1 -2 3


## 예제 출력 2

5


## 예제 입력 3

5
-1 -3 0 -5 -4


## 예제 출력 3

0