#include <iostream>
#include <vector>
#include <numeric>
#include <iterator>
#include <climits>
using namespace std;

int main(void){
	int N;
	while (cin >> N, N) {
		vector<int> a(N);
		for (int i = 0; i < N; i++)
			cin >> a[i];
		vector<int> sums;
		sums.push_back(0);
		partial_sum(a.begin(), a.end(), back_inserter(sums));

		int m = INT_MIN;
		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				m = max(m, sums[j + 1] - sums[i]);
			}
		}

		cout << m << endl;
	}
}