#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;

int gcd(long long int m,long long int n){
	while(m!=n){
		if(m>n){m=m-n;
		}
		else n=n-m;
	}
	return m;
}
int lmc(long long int m,long long int n){
return m*n/gcd(m,n);
}

int main(){
int n;
while (cin>>n){
	if (n==0){
		break;
	}
	int a[5000];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	int temp=-100000;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=n-i;j++){
			int sum=0;
			for (int k=0;k<i;k++){
				sum+=a[j+k];
			}
			if (temp<sum){
				temp=sum;
			}

		}

	}
	cout<<temp<<endl;
}

}