#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = { 1,0,-1,0,1,1,-1,-1 };
int dy[8] = { 0,1,0,-1,1,-1,1,-1 };


int main() {

	int n;

	while (cin >> n) {
		if (n == 0)break;

		vector<int> a(n);

		for (int i = 0; i < n; i++)cin >> a[i];

		vector <int> s(n + 1, 0);

		for (int i = 0; i < n; i++) {
			s[i + 1] = s[i] + a[i];
		}

		int maxi = -INF;

		for (int i = n; i > 0; i--) {
			for (int j = i - 1; j >= 0; j--) {
				maxi = max(maxi, s[i] - s[j]);
			}
		}

		cout << maxi << endl;
	}


		return 0;
	}

