#abc189c. [abc189_c]Mandarin Orange

[abc189_c]Mandarin Orange

Problem Statement

There are NN dishes arranged in a row in front of Takahashi. The ii-th dish from the left has AiA_i oranges on it.

Takahashi will choose a triple of integers (l,r,x)(l, r, x) satisfying all of the following conditions:

  • 1leqlleqrleqN1\\leq l \\leq r \\leq N;
  • 1lex1 \\le x;
  • for every integer ii between ll and rr (inclusive), xleAix \\le A_i.

He will then pick up and eat xx oranges from each of the ll-th through rr-th dishes from the left.

At most how many oranges can he eat by choosing the triple (l,r,x)(l, r, x) to maximize this number?

Constraints

  • All values in input are integers.
  • 1leqNleq1041 \\leq N \\leq 10^4
  • 1leqAileq1051 \\leq A_i \\leq 10^5

Input

Input is given from Standard Input in the following format:

NN A1A_1 ldots\\ldots ANA_N

Output

Print the maximum number of oranges Takahashi can eat.


Sample Input 1

6
2 4 4 9 4 9

Sample Output 1

20

By choosing (l,r,x)=(2,6,4)(l,r,x)=(2,6,4), he can eat 2020 oranges.


Sample Input 2

6
200 4 4 9 4 9

Sample Output 2

200

By choosing (l,r,x)=(1,1,200)(l,r,x)=(1,1,200), he can eat 200200 oranges.