#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[5010],dp[5010],ans;

int main(void){
	while(1){
		cin>>n;
		if(n==0)break;
		reg(i,1,n)cin>>a[i];
		dp[0]=0;
		reg(i,1,n)dp[i]=max(dp[i-1]+a[i],a[i]);
		ans=-1e18;
		reg(i,1,n)ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
	return 0;
}
