#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int n,p,m;
	int number[5000];
	int sum=0,max=0;

	scanf("%d",&n);

	while(n != 0){
		memset(number,'\0',sizeof(number));
		for(int i=0;i<n;i++){
			cin >> p;
			number[i] = p;
		}

		for(int i=0;i<n;i++){
			m = n;
			while(0 < m){
				for(int j=m-1;j>=i;j--){
					sum += number[j];
				}
				m--;
				if(sum > max){
					max = sum;
				}
				sum = 0;
			}
			m=n;
		}
		cout << max << endl;

		sum = max = 0;
		scanf("%d",&n);
	}
}