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.

data structures

greedy

*3200

No tag edit access

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

×
E. Bear and Bowling

time limit per test

6 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputLimak is an old brown bear. He often goes bowling with his friends. Today he feels really good and tries to beat his own record!

For rolling a ball one gets a score — an integer (maybe negative) number of points. Score for *i*-th roll is multiplied by *i* and scores are summed up. So, for *k* rolls with scores *s*_{1}, *s*_{2}, ..., *s*_{k}, total score is . Total score is 0 if there were no rolls.

Limak made *n* rolls and got score *a*_{i} for *i*-th of them. He wants to maximize his total score and he came up with an interesting idea. He will cancel some rolls, saying that something distracted him or there was a strong wind.

Limak is able to cancel any number of rolls, maybe even all or none of them. Total score is calculated as if there were only non-canceled rolls. Look at the sample tests for clarification. What maximum total score can Limak get?

Input

The first line contains single integer *n* (1 ≤ *n* ≤ 10^{5}).

The second line contains *n* space-separated integers *a*_{1}, *a*_{2}, ..., *a*_{n} (|*a*_{i}| ≤ 10^{7}) - scores for Limak's rolls.

Output

Print the maximum possible total score after choosing rolls to cancel.

Examples

Input

5

-2 -8 0 5 -3

Output

13

Input

6

-10 20 -30 40 -50 60

Output

400

Note

In first sample Limak should cancel rolls with scores - 8 and - 3. Then he is left with three rolls with scores - 2, 0, 5. Total score is 1·( - 2) + 2·0 + 3·5 = 13.

In second sample Limak should cancel roll with score - 50. Total score is 1·( - 10) + 2·20 + 3·( - 30) + 4·40 + 5·60 = 400.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/24/2024 22:54:39 (k2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|