#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<long long int> hyou(n+1, 0);
		long long int a;
		long long int MAX = 0;
		int maxn = 0;
		for (int i = 0; i < n; i++) {
			cin >> a;
			hyou[i+1] = hyou[i] + a;
			if (i == 0) {
				MAX = hyou[1];
				maxn = 1;
			} else {
				if (hyou[i+1] > MAX) {
					MAX = hyou[i+1];
					maxn = i+1;
				}
			}
		}
		long long int MIN = 0;
		int minn = 0;
		for (int i = 1; i < maxn; i++) {
			if (hyou[i] < 0) {
				if (hyou[i] < MIN) {
					MIN = hyou[i];
					minn = i;
				}
			}
		}
		if (minn != 0) {
			MAX -= MIN;
		}
		cout << MAX << endl;
	}
	return 0;
}