// start 20:09
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )

using namespace std;

int main() {
    int n;
    vector<int> nums(5001);
    
    while(cin >> n, n) {
        int max_n;

        REP(i, n) cin >> nums[i];

        // cout << nums[0] << " " << nums[1] << " " << nums[2] << endl;        
        max_n = nums[0];

        // cout << "m:" << max_n << endl;

        REP(oft, n) {
            int sum = 0;
            for ( int i = oft; i < n; i++ ) {
                sum += nums[i];
                max_n = max(max_n, sum);
            }
        }
        cout << max_n << endl;
    }

    return 0;
}