#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n,a[5010],b[5010];
signed main(){
	while(true){
		cin>>n;
		if(!n)break;
		rep(i,n){
			cin>>a[i];
			if(i)a[i]+=a[i-1];
		}
		rep(i,n){
			if(i)b[i]=min(b[i-1],a[i]);
			else b[i]=min((ll)0,a[i]);
		}
		int ans=-INF;
		rep(i,n){
			ans=max(ans,a[i]-b[i-1]);
		}
		cout<<ans<<endl;
	}
	return 0;
}
