#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int num[5001] = {};
		int maxim = -100001;
		if (n == 0) break;
		for (int i = 0; i < n; i++) cin >> num[i];
		for (int i = 0; i < n ; i++)
		{
			int sum = 0;
			for (int j = i; j < n; j++)
			{
				sum += num[j];
				maxim = (maxim >= sum) ? maxim : sum;
			}
		}
		cout << maxim << endl;
	}
	return 0;
}
