#include<iostream>
#include<cmath>
using namespace std;
int n,num,t,tmax;
int main(){
int i;
cin>>n>>num;tmax=num;
for(i=1;i<n;i++){
cin>>t;
if(num<0)num=0;
num+=t;
tmax=tmax>num?tmax:num;
}
cout<<tmax<<endl;
return 0;
}
https://www.luogu.com.cn/problem/P1115