#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long long int keisan(int start, int end, vector<int> hyou) {
	long long int sum = 0;
	for (int i = start; i <= end; i++) {
		sum += hyou[i];
	}
	return sum;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> hyou(n);
		for (int i = 0; i < n; i++) {
			cin >> hyou[i];
		}
		long long int sum;
		long long int MAX = keisan(0, 0, hyou);
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				sum = keisan(i, j, hyou);
				MAX = max(sum, MAX);
			}
		}
		cout << MAX << endl;
	}
	return 0;
}