#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int num;
    while (cin >> num, num) {
        vector<int> a(num);
        cin >> a[0];
        for (int i = 1; i < num; i++) {
            cin >> a[i];
            a[i] = max(a[i - 1] + a[i], a[i]);
        }
        cout << *max_element(a.begin(), a.end()) << endl;
    }
    return 0;
}
