#include <iostream>
#include <vector>

using namespace std;

int main()
{
	while(true)
	{
		int length;
		cin >> length;
		if(length == 0)
			break;

		auto numbers = vector<int>(length);
		for(auto& i : numbers)
			cin >> i;

		int max = -2000001;
		for(int i = 0; i < length; i++)
		{
			int current = 0;
			for(int j = i; j < length; j++)
			{
				current += numbers[j];
				if(max < current)
					max = current;
			}
		}

		cout << max << endl;
	}

	return 0;
}