#include <cstdio>
#include <iostream>

using namespace std;

int main(void){
	int n, a[5000], res[5000], sum, i, j, ans;
	while(1){
		scanf("%d",&n);
		if(!n){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d",&a[i]);
		}
		sum = 0;
		for(i = 0;i < n;i++){
			sum += a[i];
			res[i] = sum;
		}
		ans = res[0];
		for(i = 0;i < n;i++){
			ans = max(ans,res[i]);
			for(j = 0;j < i;j++){
				ans = max(ans,res[i] - res[j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}