#include<cstdio>
#include<algorithm>

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