Edoardo has a ranch in Pordenone, surrounded by tall mountains on three sides. Since his cows are always trying to escape, he built a fence on the fourth side, but soon realised that he does not need all of it. The fence consists of wooden poles, indexed from to , and pole has a height of centimeters.
After removing some poles, the robustness of the remaining ones is the sum of over all such that poles and have not been removed and all those between them have been removed. Help Edoardo compute the maximum possible robustness over all possible choices of poles to remove.
Input data
The first line contains the integer : the number of poles. The second line contains integers : the height of the poles.
Output data
You need to write a single line with an integer: the maximum possible robustness over all possible choices of poles to remove.
Constraints and Clarifications
- .
- for each .
# | Score | Restrictions |
---|---|---|
1 | 0 | Examples. |
2 | 17 | . |
3 | 30 | . |
5 | 53 | No additional limitations. |
Example 1
stdin
4
10 4 8 7
stdout
23
Explanation
In the first sample case, it is optimal to only remove pole . The robustness of the remaining poles () is:
.
Example 2
stdin
10
5 4 18 11 19 14 21 7 0 10
stdout
114