#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;

ll ara[10000];
int main()
{
    ll n;
    while(scanf("%lld", &n))
    {
        if(n==0) break;
        for(ll i=1; i<=n; i++){
            scanf("%lld", &ara[i]);
        }

        ll p = 0;
        for(ll i = 1; i <= n; i++){
            ll s = 0;
            for(ll j = i; j <= n; j++){
                s += ara[j];
                p = max(p,s);
            }
        }
        printf("%lld\n", p);
    }

    return 0;
}