/*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	int n, S[5000] = { 0 }, numsMax = 0;
	while(1) {
		cin >> n;
		if(n == 0) { break; }
		for(int i = 0; i < n; i++) {
			cin >> S[i];
		}
		numsMax = 0;
		for(int i = 0; i < n; i++) {
			int preSum = 0;
			for(int j = i; j < n; j++) {
				preSum += S[j];
				numsMax = max(preSum, numsMax);
			}
		}
		cout << numsMax << endl;
	}
}