#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
int main(){
    while(1){
        ll n,ans=-10000000000;
        cin >> n;
        if(n==0)    break;
        vector<ll> a(n);
        for(ll i=0;i<n;i++) cin >> a[i];
        for(ll i=0;i<n;i++){
            ll sum=0;
            for(ll j=i;j<n;j++){
                sum+=a[j];
                ans = max(sum,ans);   
            }
        }
        cout << ans << endl;
    }
    return 0;
}
