#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

int main(int argc, char const* argv[])
{
    
    do {
        int n, b, maximum = -100001, current = 0;

        scanf("%d ", &n);
        if(n == 0) break;

        for (int i = 0; i < n; i++) {
            scanf("%d ", &b);
            current += b;
            if(maximum < current){
                maximum = current;
            }
            if(maximum < b){
                maximum = current = b;
            }
        }

        printf("%d\n", maximum);
    } while (1);
    
    return 0;
}