#include <iostream>
#include <cstdio>
using namespace std;


int main()
{
    int sum;
    int currentSum;
	int loop;
	int a[5005];

	while (cin >> loop, loop) {
	    // O(n)
	    for(int i=0; i<loop; i++){
	        cin >> a[i];
	    }
	    
	    // O(n^2)
	    sum=0, currentSum=0;
	    for(int j=0; j<loop; j++){
	        for(int k=j; k<loop; k++){
	            //cout << "k : " << k << endl;
	            currentSum += a[k];
	            if(currentSum > sum){
	                sum = currentSum;
	            }
	        }
	        currentSum = 0;
	    }
        cout << sum << endl;
	}
	return 0;
}
