#include <iostream>
#include <vector>

using namespace std;

int calc (vector<int> a, int i, int n) {
    int s = 0, j;
    for (j = 0; j < n; j++) {
        s += a[i + j];
    }
    return s;
}

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        vector<int> a(n);
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0, s;
        for (i = 1; i <= n; i++) {
            for (j = 0; j + i <= n; j++) {
                s = calc(a, j, i);
                sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}