#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (!n) break;

		vector<int> v(n);
		for (int i = 0; i < n; i++) {
			cin >> v.at(i);
		}

		int64_t max = -100000 * 5001;
		for (int i = 0; i < n; i++) {
			int64_t x = 0;
			for (int j = i; j < n; j++) {
				x += v.at(j);
				if (x > max) {
					max = x;
				}
			}
		}

		cout << max << endl;
	}
}
