#include<iostream>
#include<vector>
#include<limits>
#include<numeric>

using namespace std;

int main() {

	int n;
	while (cin >> n, n != 0) {
		vector<int> data(n);
		for (int& temp : data) {
			cin >> temp;
		}

		int sum_max = numeric_limits<int>::min();
		for (auto it1 = data.begin(); it1 != data.end(); ++it1) {
			int temp = numeric_limits<int>::min();
			auto it2 = it1;
			do {
				++it2;
				int sum = accumulate(it1, it2, 0);
				if (sum > temp) {
					temp = sum;
				}

				if (sum_max < temp) {
					sum_max = temp;
				}
			} while (it2 != data.end());
		}
		cout << sum_max << endl;
	}

	return 0;
}