A small shop records its daily profit (negative means loss). The owner wants to find the best stretch of consecutive days, the one with the biggest total profit.
Find the maximum sum of any non-empty contiguous subarray.
Input Format The first line has n. The second line has n integers.
Output Format Print the maximum subarray sum.
Constraints • 1 ≤ n ≤ 10^5 • -10^4 ≤ value ≤ 10^4
Examples
Example 1
Input
9
-2 1 -3 4 -1 2 1 -5 4
Output
6
Explanation The stretch 4, -1, 2, 1 gives 6.
Example 2
Input
3
-5 -1 -8
Output
-1
Explanation All losses: the best is the smallest loss, -1.
Example 3
Input
4
5 4 -1 7
Output
15
Explanation Take everything: 5 + 4 - 1 + 7 = 15.
Acceptance—
Accepted0
Submissions0
Auto-save
SavedLn 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
6
No results yet
Run your code to test it against the sample cases.