// 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 sum(vector<int> &nums, int oft, int len) {
    int ret = 0;
    for ( int i = oft; i < len; i++ ) {
        ret += nums[oft+i];
    }
    return ret;
}

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

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

        REP(oft, n) for( int len = 1; len <= n-oft; len++ ) {
            // cout << oft << " " << len << endl;
            max_n = max(max_n, sum(nums, oft, len));
        }
        cout << max_n << endl;
    }

    return 0;
}