/*
?????????: Maximum Sum Sequence
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
?????°: 
19:13:12 ?°?????????§??????
19:26:09 ?°??????????????????§???????´????????????????
19:26:28 ????´???????????°??????????????´????????????§????????????????????¨??¢?´¢??§5000^2 ... ????????????
19:32:27 ???????????????
*/
#include <iostream>
#include <vector>
using namespace std;


int main()
{
	while(true){
		int n; cin >> n; if(n == 0) {return 0;}
		vector<int> arr;
		for(int i=0; i<n; i++) {
			arr.push_back(0);
			cin >> arr[i];
		}

		vector<int> sums;
		// sums[0] = 0;
		// sums[1] = sums[0] + arr[0]
		sums.push_back(0);
		for(int i=0; i<n; i++) {
			sums.push_back(sums[i] + arr[i]);
		}

		int ans = -100000;
		for(int i=0; i<n; i++) { 
			for(int j = i+1; j <= n; j++){
				ans = max(ans, sums[j] - sums[i]);
			}
		}

		cout << ans << endl;
	}
}