#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> maxSum(n);
		int a;
		cin >> a;
		maxSum[0] = a;
		int max = -999999999;
		for(int i = 1; i < n; ++i)
		{
			cin >> a;
			if(maxSum[i - 1] + a < a)
			{
				maxSum[i] = a;
			}
			else
			{
				maxSum[i] = maxSum[i - 1] + a;
			}
			if(max < maxSum[i])
			{
				max = maxSum[i];
			}
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}