#include <stdio.h>

#define SGN(X) ((X)>0?1:(X)<0?-1:0)
int compressRead(int a[], int n);

int main(void){
	int n;
	int a[5000];
	int max, cur;
	
	while (scanf("%d", &n), n){
		n = compressRead(a, n);
/*		printf("a[%d]:", n);
		for (int i=0; i<n; i++){
			printf("%d ", a[i]);
		}
		puts(""); */
		max = a[0];
		for (int i=0; i<n; i++){
			cur = 0;
			for (int j=i; j<n; j++){
				cur += a[j];
				if (cur > max) max = cur;
			}
		}
		printf("%d\n", max);
		for (int i=0; i<n; i++) a[i]=0;
	}
	
	return 0;
}

int compressRead(int a[], int n){
	int idx=0;
	int x,last;
	
	scanf("%d", &x);
	last=a[idx]=x;
	for (int i=1; i<n; i++){
		scanf("%d", &x);
		if (x==0) continue;
		if (x<0){
			a[++idx] = x;
//			printf("a[%d] = \%d\n",idx,x);
		}else{
			if (last<0) a[++idx]=0;
			a[idx]+=x;
//			printf("a[%d] += %d (=%d)\n", idx, x, a[idx]);
		}
		last = x;
	}
	
	return idx+1;
}