#include<iostream>  
#include<algorithm>  
#include<cstdio>  
#include<cstring>  
#include <deque> 
using namespace std;  

bool state = false ;

int main()
{
	int n ;
	while(1)
	{
		cin >> n ;
		if( ! n ) return 0 ;
		
		int * p = new int [n] ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			cin >> p[i] ;
		}
		
		int max , pos_b , pos_e , contain ;
		max = pos_b = pos_e = contain = 0 ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			if(contain < 0) contain = 0 ;
			else 
			{
				contain += p[i] ;
			}
			
			if(contain > max) max = contain ;
		}
		
		if(state) cout << endl ;
		state = true ;
		cout << max ;
	} 
	return 0 ;
 } 