#include<iostream>
using namespace std;

int main() {
	int i, j, n, a, max_so_far, max_ending_here;
	
	while (1) {
		cin >> n;
		if (n == 0)break;
		max_so_far = 0;
		max_ending_here = 0;
		for (i = 0; i < n; i++) {
			cin >> a;
			max_ending_here = max_ending_here + a;
			if (max_ending_here < 0)max_ending_here = 0;
			if (max_so_far < max_ending_here)max_so_far = max_ending_here;
			if (max_so_far < a)max_so_far = a;
		}
		cout << max_so_far << endl;

	}

	return 0;
}