#include <iostream>
#include <vector>

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 = a[0];
		for(int len=1; len<=a.size(); len++){
			for(int begin=0; begin<a.size()-len+1; begin++){
				long long int sum = 0;
				for(int i = begin; i < begin + len; i++){
					sum += a[i];
				}
				if(sum > max_sum){
					/*std::cout << begin << ',' << len << std::endl;*/
					max_sum = sum;
				}
			}
		}
		std::cout << max_sum << std::endl;
		a.clear();
	}
	return 0;
}