#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	while (cin >> n && n != 0) {
		vector<int> num(n);
		for (int i=0; i<n; i++) {
			cin >> num[i];
		}
		int m=0,sum=0;
		for (int i=0; i<n; i++) {
			sum=num[i];
			for (int j=i+1; j<n; i++) {
				sum += num[j];
				m = max(m, sum);
			}
		}
		cout << m << endl;
	}
	return 0;
}