#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
//#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    while(true){
        ll n;
        cin>>n;
        if(n==0)break;
        ll l[n+1];
        l[0]=0;
        for(int i=1;i<n+1;i++){
            int x;
            cin>>x;
            l[i]=l[i-1]+x;
        }
        ll ans=-1000000;
        for(int i=0;i<n+1;i++){
            for(int j=i+1;j<n+1;j++){
                ans=max(ans,l[j]-l[i]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

