#include <iostream>
#include <vector>

long long int sum(const std::vector<int> &a, int begin, int end){
	long long int s = 0;
	for(int i=begin; i<end; i++){
		s += a[i];
	}
	return s;
}

int main() {
	int n;
	std::vector<int> a;
	while(std::cin >> n, n){
		for(;n--;){
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		long long int max_sum = sum(a, 0, a.size());
		for(int len = a.size() - 1; len--;){
			for(int begin = 0; begin < a.size() - len + 1; begin++){
				if(begin && a[begin-1] > 0)
					continue;
				if(a[begin+len] > 0)
					continue;
				long long int s = sum(a, begin, begin + len);
				if(s > max_sum){
					max_sum = s;
				}
			}
		}
		std::cout << max_sum << std::endl;
		a.clear();
	}
	return 0;
}