#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		vector<int> a;
		for(int i=0;i<n;i++){
			int b;
			cin>>b;
			a.push_back(b);
		}
		vector<int> sum;
		for(int j=0;j<a.size();j++){
			int s=0;
			for(int k=j;k<a.size();k++){
				s += a[k];
				sum.push_back(s);
			}
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}