#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[5000];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int best=0;
	for(int lon=1;lon<=n;lon++){
		for(int first=0;first+lon<=n;first++){
			int count=0;
			for(int k=0;k<lon;k++)
				count+=a[first+k];
			if(count>best)
				best=count;
		}
	}
	cout<<best<<endl;
	}
	return 0;
}