public static int SumArray()
{
var arr = new int[]{ -2, -4, -5, -6, -7, -89, -56 };
var sum = 0;
var max = arr[0];
foreach (var item in arr)
{
sum += item;
// sum = Math.Max(sum,0); resting here will not give expected output
max = Math.Max(sum,max);
sum = Math.Max(sum,0);
}
return max;
}
var maxSequence = function(arr){
var min = 0, ans = 0, i, sum = 0;
for (i = 0; i < arr.length; ++i) {
sum += arr[i];
min = Math.min(sum, min);
ans = Math.max(ans, sum - min);
}
return ans;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i = 0;i<n;i++){
cin>>a[i];
}
int s = 0;
int mx = INT_MIN;
for(int i =0;i<n;i++){
s+=a[i];
if(s<0){
s=0;
}
mx = max(s,mx);
}
cout<<mx;
return 0;
}