#include <stdio.h>

int main(void)
{
	long num[10000], sum, max;
	int n, i, j, k;
	
	while (scanf("%d", &n), n != 0){
		sum = 0;
		max = 0;
		for (i = 0; i < n; i++)scanf("%ld", &num[i]);
		for (i = 0; i < n - 1; i++){
			sum = num[i];
			for (j = i + 1; j < n; j++){
				sum += num[j];
				if (max < sum)max = sum;
			}
		}
		
		printf("%ld\n", max);
	}
	
	return (0);
}