Maximize Non-Negative SumEasy

Maximize Non-Negative Sum

EasyPractice library · +10 XPgreedyarrays

Given a list of N integers, you need to select some numbers such that their sum is maximized. You can only select non-negative numbers. If there are no non-negative numbers, select none and the sum is 0. Print the maximum possible sum.

Input

The first line contains an integer N. The second line contains N integers, separated by spaces.

Output

Print a single integer representing the maximum possible sum.

Constraints

1 <= N <= 1000 -1000 <= A_i <= 1000, where A_i is the i-th integer.

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5
1 2 -3 4 -5
Output
7

Sum of positive numbers: 1 + 2 + 4 = 7.

Example 2

Input
3
-1 -2 -3
Output
0

No positive numbers, so the maximum sum is 0.

Hints