#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    int n;
    while (cin >> n){
        if (n == 0) break;
        int num[n], sum[n], max;
        REP(i, n){
            cin >> num[i];
            if (i != 0 && sum[i-1]+num[i] > num[i]){
                sum[i] = sum[i-1] + num[i];
                if (max < sum[i]) max = sum[i];
            } else {
                sum[i] = num[i];
                if (i == 0) max = sum[i];
                else if (max < sum[i]) max = sum[i];
            }
        }
        cout << max << endl;
    }
}
