#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int main() {
	int n;
	while (cin >> n && n) {
		long long a[6000];
		a[0] = 0;
		for (int l = 0; l < n; l++) {
			cin >> a[l + 1];
		}
		for (int l = 1; l <= n; l++) {
			a[l] += a[l - 1];
		}
		long long ans = 0;
		for (int l = 0; l < n; l++) {
			for (int r = l + 1; r <= n; r++) {
				ans = max(ans, a[r] - a[l]);
			}
		}
		cout << ans << endl;
	}




	return 0;
}