#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;





int main()
{
	int n;
	long long a[5000];
	long long b[5000];//i???????????§??????
	long long m, M;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < n; i++) {
			if (i == 0) b[i] = a[i];
			else b[i] = b[i - 1] + a[i];
		}
		for (int i = 0; i < n; i++) {
			if (i == 0) {
				m = min({ (long long)0,b[0] });
				M = max({ (long long)0,b[0] });
			}
			else {
				if (b[i] - m > M) {
					M = b[i] - m;
				}
				if (b[i] < m) {
					m = b[i];
				}
			}
		}
		if (M == 0 && b[0] < 0) {
			for (int i = 0; i < n; i++) {
				if (i == 0) M = b[i];
				else {
					if (b[i] > M) M = b[i];
				}
			}
		}
		cout << M << endl;
	}
		





}