#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

typedef long long ll;
using namespace std;

int main()
{
	int T;
	int maxS=numeric_limits<int>::min();
	while(~scanf("%d",&T)){
		int* dp = new int[T+1]();
		if(T==0) break;
		for(int t=0;t<T;t++){
			int tmp;
			scanf("%d",&tmp);
			dp[t+1] = max(dp[t] + tmp,tmp);
			//printf("dp[%d+1] = %d,dp[%d] = %d\n",t,dp[t+1],t,dp[t]);
		}

		sort(dp,dp+T+1,greater<int>());
		cout << dp[0] << endl;

		delete[] dp;
	}
}