#include <algorithm>
#include <iostream>
using namespace std;
int a[5010];
int main(){
	int i,n,max_so_far,max_ending_here;//maximum subarray problem
	cin>>n;
	while(n!=0){

		for(i=0;i<n;i++){
			cin>>a[i];
		}

		max_ending_here=0;
		max_so_far=0;
		
		for(i=0;i<n;i++){
			max_ending_here = max(0,max_ending_here + a[i]);
			max_so_far = max(max_so_far,max_ending_here);
		}
	cout << max_so_far << endl;
	cin>>n;//kousinn
	}
}