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


int main()
{
	int n, a[5001];
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		int maxseq = -100001;
		for (int i = 0; i < n; i++){
			int sum = 0;
			for (int j = 0; i + j < n; j++){
				sum += a[i + j];
				maxseq = max(maxseq, sum);
			}
		}
		cout << maxseq<<endl;
	}
	return 0;
}