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

constexpr int INF = 1e9;

int solve (int n) {
	int ans = -INF, sum = 0;
	for (int i = 0; i < n; i++) {
		int e; cin >> e;
		sum = max(sum + e, e);
		ans = max(ans, sum);
	}
	return ans;
}

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n > 0) cout << solve(n) << '\n';
		else break;
	}
	return 0;
}
