#include<iostream>
#include<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        long int t;
        cin >> t;
        /*s[0]=t;max = t;min=t;*/
        s[0] = t;
        long int max = t;
        
        for(int i=1;i<n;i++){
            cin >> t;
            s[i] = s[i-1]+t;
            if(s[i]>max)max=s[i];
            for(int j=0;j<i+1;j++)
            {
                if((s[i]-s[j])>max) max = (s[i]-s[j]);
            }
        }
        cout << max << endl;

    }

    return 0;
}