#include<stdio.h>	
int main(){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0)break;
		int a[5100];
		for(int i=0;i<n;i++)scanf("%d",&a[i]);
		int max =-100000,sum;
        for(int j=0;j<n;j++){
            sum = 0;
            for(int k=j;k<=n-1;k++){
                sum += a[k];
                max = (max >= sum)? max:sum;}}
		printf("%d\n",max);}
		return 0;}
