#include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n;
	while(cin >> n, n){
		int a[5001];
		int ans = -100000;
		for(int i = 0 ; i < n ; i++){
			cin >> a[i];
			if(i){
				a[i] = max(a[i], a[i-1] + a[i]);	
			}
			ans = max(ans, a[i]);
		}
		cout << ans << endl;
	}
	return 0;
}