#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef vector <int> vi;

int maxv(vi &x){
	int tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}


int main(void){
	int n;
	vi x;
	while (cin>>n){
		int s=INT_MIN;
		if (n==0) break;
		for (int i=0; i<n; i++){
			int n2;
			cin>>n2;
			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			if (i==0 || n2>0) s=max(s, maxv(x));
		}
		cout<<s<<endl;
		x.clear();
	}

	return 0;
}