#include<iostream>
using namespace std;

int main() {
	int n;
	while (cin >> n && n) {
		int a[5001], min, max_a;
		min = a[0] = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i == 1) max_a = a[i] - a[0];
			a[i] += a[i - 1];
			if (a[i] - min > max_a) max_a = a[i] - min;
			if (a[i] < min) min = a[i];
		}
		cout << max_a << endl;
	}
}
