#ABC189C. [ABC189C] Mandarin Orange

[ABC189C] Mandarin Orange

Score : 300300 points

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:

  • 1lrN1\leq l \leq r \leq N;
  • 1x1 \le x;
  • for every integer ii between ll and rr (inclusive), xAix \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.
  • 1N1041 \leq N \leq 10^4
  • 1Ai1051 \leq A_i \leq 10^5

Input

Input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Print the maximum number of oranges Takahashi can eat.

6
2 4 4 9 4 9
20

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

6
200 4 4 9 4 9
200

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