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

using i64 = long long int;

i64 acc[5003]={0};

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<i64> v;
        for(int i=0;i<n;++i){
            i64 a;
            cin >> a;
            v.push_back(a);
        }
        for(int i=0;i<n;++i){
            acc[i+1] = acc[i] + v[i];
        }

        i64 ans = LLONG_MIN;
        for(int i=1;i<=n;++i){
            for(int j=i;j<=n;++j){
                ans = max(ans, acc[j] - acc[i-1]);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

