#include <stdio.h>

int arr[5000];

int p14(int size) {
	int i=0;
	int j=0;
	int sum = 0;
	int smax = -10000000;
	
	int s = 0;
	
	for (int t=0; t<size; t++) {
		sum+=arr[t];
		
		if ( sum > smax ) {
			i = s;
			j = t;
			smax = sum;
		}
		
		if (sum < 0 ) {
			for(; s<t; s++) {
				sum -= arr[s];
				if ( sum > smax ) {
					i = s;
					j = t;
					smax = sum;
				}
			}
		}
	}
	
	printf("%d-%d  sum: %d\n", i, j, smax);
	return smax;
}

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if ( n==0 ) { return 0; }
		
		for(int i=0; i<n; i++) {
			scanf("%d", &arr[i]);
		}
		
		printf("%d\n", p14(n));
	}
}