It's Rar's meal time again. This time, he has obtained N delicious (and some not-so-delicious) salmon in a row. The ith salmon from the left has tastiness Ti.
This time, he decides that he is quite full, so he plans to consume it in two seperate meals. For each meal, he can choose a contiguous segment of salmon to eat (possibly none), and his total satisfaction at the end of the day would be the sum of all the salmon he has eaten. Obviously, he cannot eat the same salmon twice.
Help Rar find out what is the maximum satisfaction he can get.
The first line of input will contain one integer, N.
The second line of input will contain N integers, representing the array T.
The output should contain one integer, the maximum satisfaction Rar can get.
|Ti| ≤ 109
Subtask 1 (10%): 1 ≤ N ≤ 50.
Subtask 2 (22%): 1 ≤ N ≤ 300.
Subtask 3 (29%): 1 ≤ N ≤ 2 000.
Subtask 4 (39%): 1 ≤ N ≤ 500 000.
Subtask 5 (0%): Sample Testcases
6 5 6 -10 4 -1 6
20
5 2 -1 5 0 -2
7
Subtask | Score |
---|---|
1 | 10 |
2 | 22 |
3 | 29 |
4 | 39 |
5 | 0 |