#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll now=0,ans=-1e5;
	int n;cin>>n;
	for (int i = 1; i <= n; i++)
	{
		int x;cin>>x;
		now+=x;ans=max(ans,now);
		if(now<0)now=0;
	}
	cout<<ans;
	return 0;
}