#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	long max, sum, ans;
	while (true) {
		cin >> n;
		if (n == 0) break;
		vector<int> array(n);
		for (int i = 0;i < n;i++) {
			cin >> array[i];
		}

		for (int j = 0;j < n - 1;j++) {
			max = array[j] + array[j + 1];
			sum = array[j];
			for (int i = j + 1;i < n;i++) {
				sum += array[i];
				if (sum > max) {
					max = sum;
				}
			}
			if (j == 0) {
				ans = max;
			}
			else if (max > ans) {
				ans = max;
			}
		}
		if (array[n - 1] > ans) {
			ans = array[n - 1];
		}


		cout << ans << endl;
	}

	return 0;
}