#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];

    int min_e=*min_element(a.begin(), a.end());
    int max_e=*max_element(a.begin(), a.end());
    if (max_e < 0) {
        printf("%d\n", max_e);
    } else if (min_e < 0) {
        printf("%d\n", max_e-min_e);
    } else {
        printf("%d\n", max_e);
    }
    return 0;
}

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

    return !solved;
}