#include <iostream>
using namespace std;
long int n,a[5000];
int main(){
	int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = 0;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n-1;i++){
			tmp += a[i];
			for(j=i+1;j<n;j++){
				tmp += a[j];
				if(t < tmp) t = tmp;
			}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}