#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int n;
	int a[5000] = { 0 };

	while (cin >> n, n){
		int ans = -100000;
		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];
				ans = max(sum, ans);
			}
		}
		cout << ans << endl;
	}

	return 0;

}