#include <iostream>
using namespace std;
const int N = 2e5+10;
int w[N];
int f[N];
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>w[i];
int res=-1e9;
for(int i=1;i<=n;i++)
{
f[i]=max(f[i-1]+w[i],w[i]);//连续还是自立门户
res=max(res,f[i]);
}
cout<<res;
return 0;
}