#include <stdio.h>

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = 0;
	scanf("%d", &a);
	b[0] = s = a;

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s * a >= 0){
			b[c] += a;
		}else{
			b[++c] = s = a;
		}
	}

	int m = b[0] < 0 ? 0 : b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(m < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}