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