#include<cstdio>
#include<iostream>

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

	while(1){
		cin>>n;
		wa=0;
		for(int i=0;i<n;i++) cin>>a[i];
		max=a[0];
		for(int i=n-1;i>=0;i--){
			wa+=a[i];
			if(wa<0) wa=0;
			if(wa>max) max=wa;
		}
		cout<<max<<endl;
	}
	return 0;
}