#include<bits/stdc++.h>
using namespace std;

int a[5001]={0};

int main(){
    int n;
    while(cin >> n, n != 0){
        for(int i=0;i<n;++i)cin >> a[i];
        int maxi = INT_MIN;
        for(int i=0;i<n;++i){
            int sum = a[i];
            if(sum > maxi)maxi = sum;
            for(int j=1;i+j<n;++j){
                sum += a[i+j];
                if(sum > maxi)maxi = sum;
            }
        }
        cout << maxi << endl;
    }

    return 0;
}
