#include <iostream>
using namespace std;

int main() {
int n,b;
int a[5001];
while(1){
	cin>>n;
	if(n==0){
		break;
	}
	for (int kkk=1;kkk<=5001;kkk++){
		a[kkk]=0;
	}
	for (int kk=1;kk<=n;kk++){
		cin>>b;
		a[kk]=b;
	}
	int high=a[1];
	for (int k=1;k<=n;k++){
		for(int l=k;l<=n;l++){
			int sum=0;
			for(int m=k;m<=l;m++){
				sum=sum+a[m];
				if(sum>=high){
		high=sum;
			}
		}
	}
	
	}
cout<<high<<endl;
}
	return 0;
}