#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
	int a[5000];
	int n;
	int sum = 0;
	int m = 0;
	while(1){
		scanf("%d", &n);
		m = 0;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				m = max(sum, m);
			}
		}
		cout << m << endl;
	}
	return 0;
}