//640711C ???????????¬????????°???
//?????????????????????:Maximum Sum Sequence
//????????????????????????15?????????????????°5??????
//

#include <algorithm>
#include <iostream>
using namespace std;

int n,s[5000+10];

int biggest(int n){
    int M=-200000-10;
    for(int p=0;p<n;p++){
//        cout << "s[" << p << "] = " << s[p] << endl;
        if(s[p]>M) M=s[p];
        for(int q=0;q<p;q++){
//            cout << "s[" << p << "]-s[" << q << "] = " << s[p]-s[q] << endl;
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << biggest(n) << endl;
    }
}