//0022 Maximum Sum Sequece

//2<=n<=5000ÂÌñ©çA×Ú·éÌaÌÅålð¦æ
//KÉâÁ½ç°i(1¨n-1){i*(n-i)}ñÅ]TÅlÞ©
//Æè ¦¸Ag¤ñÌÉV½ÉÁíÁ½àÌð«µÄAÁ¦éàÌðø­ûjÅ¢¢©


#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;

int main(void)
{
	const int N = 5000;
	int n;
	int i, j;
	int a[N];
	while(cin >> n, n)
	{
		for(i = 0; i < n; i++)
			cin >> a[i];

		int sum, max_sum = 0;

		//iÂÌðg¤
		for(i = 1; i <= n; i++)
		{
			//Ü¸ÍAÜÆÜÁÄg¤ªÌaðvZµÄ¨­
			sum = accumulate(a, a+i, 0);
			max_sum = max(sum, max_sum);

			for(j = 0; j+i < n; j++)
			{
				//ÌÂðg¢Ü·
				sum -= a[j];
				sum += a[j+i];
				max_sum = max(max_sum, sum);
			}
		}

		cout << max_sum << endl;
	}
	return 0;
}