#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		long long int a, sum = 0, hold = 0;
		
		bool start = false;
		for(int i = 0;i < n;i++){
			cin >> a;
			if(a > 0) start = true;
			if(start){
				sum += a;
				if(hold < sum){
					hold = sum;
				}
			}
		}
		cout << hold << endl;
	}
	
	return 0;
}