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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		int maximum = 0;
		int sum = 0;

		for(int i = 0; i < n; i++){
			for(int j = 0; j <= n - i; j++){
				for(int k = 0; k < j; k++){
					sum += a[i + k];
				}
				maximum = max(maximum, sum);
				sum = 0;
			}
		}
		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}