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

int n, m, a, p, q;

int main()
{
	cin >> n;

	while (n > 0) {
		m = 0;
		p = -200000;
		q = 0;

		for (int i = 0; i < n; i++) {
			cin >> a;

			m += a;
			p = max(p, m - q);
			q = min(q, m);
		}

		cout << p << endl;
		cin >> n;
	}
}

