#include<iostream>
#include<vector>

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		for (int i = 0; i < n; i++) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		int max = 0, sum = 0;
		std::vector<int>::iterator end = a.begin(), beg = a.begin();
		for (std::vector<int>::iterator itr = a.begin(); itr != a.end(); itr++) {
			sum += *itr;
			if (sum > max) {
				max = sum;
				end = itr;
			}
		}
		sum = max;
		for (std::vector<int>::iterator itr = a.begin(); itr != end; itr++) {
			sum -= *itr;
			if (sum > max) {
				max = sum;
				beg = itr;
			}
		}
		std::cout << max << std::endl;
	}

	return 0;
}