#include <iostream>
#include <cmath>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int main(void){
	long int n , a[5005] , s[5005] , m;
	while (cin >> n && n){
		REP(i,n){
			cin >> a[i];
		}
		s[0] = 0;
		FOR(i,1,n){
			s[i] = s[i-1]+a[i-1];
		}
		m=-100000;
		REP(i,n){
			FOR(j,i+1,n+1){
				if(s[j]-s[i]>m)
					m=s[j]-s[i];
			}
		}
		cout << m << endl;
	}


	return 0;
}