#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

int main(void){
    int n,an[5100],max,sum;
    
    while (1)
    {
        cin>>n;
        if(n==0){break;}
        max=-100000;
        sum=0;
        for (int i=0; i<n; i++){cin>>an[i];}
        for(int i=0;i<n;i++)
        {
            if(max<an[i]){max=an[i];}
            sum=an[i];
            for (int j=i+1; j<n; j++)
            {
                sum += an[j];
                if (max<sum) {max=sum;}
            }
            sum=0;
        }
        cout<<max<<endl;
    }
        return 0;
}