#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

bool testcase_ends() {
    size_t n;
    scanf("%zu", &n);

    if (!n) return 1;

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    for (size_t i=1; i<n; ++i)
        a[i] += a[i-1];

    vector<int>::iterator min_=min_element(a.begin(), a.end());
    vector<int>::iterator max_=max_element(a.begin(), a.end());
    if (*min_ < 0 && min_ < max_) {
        printf("%d\n", *max_-*min_);
    } else {
        printf("%d\n", *max_);
    }
    return 0;
}

int main() {
    int solved=0;
    while (!testcase_ends())
        ++solved;

    return !solved;
}