#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);
        int t;
        /*cin >> t;
        s[0]=t;max = t;min=t;*/
        s[0] = 0;
        long int max = 0;

        for(int i=0;i<n;i++){
            cin >> t;
            s[i+1] = s[i]+t;
            for(int j=0;j<i;j++)
            {
                if((s[i+1]-s[j])>max) max = s[i+1]-s[j];
            }
        }
        cout << max << endl;

    }

    return 0;
}