#include <stdio.h>

int main(void)
{
	int i;
	long max;
	long total;
	int a[5010];
	int n;
	
	while (scanf("%d", &n), n != 0){
		max = -9999999999;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
			if (total < 0){
				total = 0;
			}
			if (max < total){
				max = total;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}