#include <iostream>

using namespace std;

int main(void){
	int n;
	int a[5000]={0};
	while(cin >> n){
		int max = 0;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			int sum = 0;
			for(int j=0;i+j<n;j++){
				sum += a[i+j];
				if(max < sum) max = sum;
			}
		}
		cout << max << "\n";
	}
	return 0;
}