#include <bits/stdc++.h>

int kadaneAlg(int arr[], const int &len) {
    int max_global;
    int max_current = max_global = arr[0];

    for (int i = 1; i < len; i++) {
        max_current = std::max(arr[i], arr[i] + max_current);
        if (max_current > max_global) max_global = max_current;
    }
    return max_global;
}

int main()
{
    int N;
    while(1) {
        std::scanf("%d", &N);
        if (N == 0) break;
        int arr[N];
        for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
        std::printf("%d\n", kadaneAlg(arr, N));
    }
    return 0;
}

