#include <iostream>
using namespace std;

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

}
	return 0;
}