#include<cstdio>
#include<algorithm>

using namespace std;
int main(void)
{
	int n,sum,log;
	while(scanf("%d",&n))
	{
		if(n == 0) break;
		int a[5001] = {0};
		for(int i = 0;i < n;i++)
		{
			scanf("%d",&a[i]);
		}
		sum = 0;
		for(int i = 0;i < n;i++)
		{
			log = 0;
			for(int j = i;j < n;j++)
			{
				log += a[j];
				if(sum < log)
				{
					sum = log;
				}
				else
				{
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}