include<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		int n;
		int a[5001];
		cin>>n;
		if(n==0)break;
		int b;
		a[0]=0;
		cin>>a[1];
		for(int i=2;i<=n;i++){
			cin>>b;
			a[i]=a[i+1]+b;
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<i;j++){
				ans=max(ans,a[i]-a[j]);
			}
		}
		cout<<ans<<endl;
	}
}
		