#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LINT;

const int MAX_N = 5000;

LINT as[MAX_N+1];

int main ( void )
{
	int n;
	while (cin >> n, n) {
		int p = 0;
		for (int i = 0; i < n; ++i) {
			LINT x;
			cin >> x;

			if (i == 0) { as[0] = x; }
			else {
				if (as[p] * x < 0) {
					as[++p] = x;
				}
				else {
					as[p] += x;
				}
			}
		}

		LINT ans = 0, sum = 0;
		for (int i = 0; i <= p; ++i) {
			sum = max(0LL, sum + as[i]);
			ans = max(ans, max(sum, as[i]));
		}

		cout << ans << endl;
	}
	return 0;
}