// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <queue>


typedef long long llong;
using namespace std;

int main() {
	int n;
	llong maxim;
	int input_num;
	int stock_sum;
	int reserve_max_neg;
	while (1) {
		cin >> n;
		if (!n)break;
		maxim = -100010;
		stock_sum = 0;
		for (int i = 0; i < n; i++) {

			cin >> input_num;
			stock_sum += input_num;
			if (stock_sum > maxim)maxim = stock_sum;
			if (stock_sum < 0)stock_sum = 0;
		}
		cout << maxim << endl;
	}
	return 0;
}
 
