#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 = a[0];
		for (std::vector<int>::iterator aitr = a.begin(); aitr != a.end(); aitr++) {
			for (std::vector<int>::iterator bitr = aitr; bitr != a.end(); bitr++) {
				int s = 0;
				for (std::vector<int>::iterator citr = aitr; citr != bitr + 1; citr++) {
					s += *citr;
				}
				max = s > max ? s : max;
			}
		}
		std::cout << max << std::endl;
	}

	return 0;
}