시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 256 MB344064942519.749%

## 문제

On Wall Street from Wonderland, we have n banks, with 10000 > n > 0. Each bank has exactly two neighbours, the left (L) and right (R) neighbour. The first bank’s left neighbour is the last bank, while the last bank’s right neighbour is the first bank. Each bank i(n>i≥0) has a capital ki with 32000>ki>-32000. The entire capital of all banks put together is known to be positive. Whenever some capital ki of bank i is negative, the Bank Fairy can do a magic move and turn the capital into a positive one. For instance, if ki=-7, after the magic move, ki=7. Unfortunately, the magic move has consequences for both neighbours of bank i. Each sees its capital reduced with the absolute value of the capital of bank i. For instance if bank L has capital kL=5 and bank R has capital kR=11, then after the magic move kL=-2 and kR=4.

Which is the minimal number of magic moves which the Bank Fairy has to do in order to make the capital of all banks greater than or equal to 0?

## 입력

On the first input line, we have the number n of banks. On the second input line, we have the capitals ki(n>i≥0) of all banks, in the order in which they are found on Wall Street from Wonderland. Each capital is separated by a single whitespace from the next one, except for the final capital which is directly followed by the newline character.

## 출력

The output contains a single line with the value of the minimal number of magic moves.

## 예제 입력 1

4
1 -2 -1 3


## 예제 출력 1

9


## 출처

• 잘못된 데이터를 찾은 사람: koosaga