#include <iostream>
#include <vector>

using namespace std;

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

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