// Arup Guha
// 11/11/2010
// Solution to 2010 SE Regional Problem G: Profits

import java.util.*;

public class g {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		
		int n = stdin.nextInt();
		
		while (n != 0) {
			
			int sum, max;
			
			// Set first term to both, since max sequence must have
			// at least one term.
			sum = stdin.nextInt();
			max = sum;
			
			// Reset sum, if necessary, because this will never
			// help you get a better max. But, max needs to stay because
			// of the one term minimum.
			if (sum < 0)
				sum = 0;
			
			// Go through the rest of the terms.
			for (int i=1; i<n; i++) {
				
				// Add in the next term.
				sum += stdin.nextInt();
				
				if (sum > max)
					max = sum;
					
				if (sum < 0)
					sum = 0;
				
			}
			
			// Print out answer.
			System.out.println(max);
			n = stdin.nextInt();
		}
	}
}