#include <iostream>
using namespace std;

int main()
{
	int n;
	while(cin>>n,n)
	{
		int data[n+1];
		int tmp=0,ans;
		data[0]=0;
		for (int i = 1; i <= n; ++i)
		{
			cin>>data[i];
		}
		for (int i = 1; i <= n; ++i)
		{
			data[i]=max(data[i-1]+data[i],data[i]);
			ans=max(ans,data[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}