#include<bits/stdc++.h>
#define INF LLONG_MAX-1
using namespace std;
typedef long long ll;

ll a[100001];
int main() {
	ll n;
	while (scanf("%lld", &n), n) {
		ll cnt = 0;
		for (ll i = 0; i < n; i++) {
			scanf("%lld", &a[i]);
			cnt += a[i];
		}
		ll Max = cnt;
		ll w = 0;
		for (ll i = 0; i < n; i++) {
			cnt -= a[i];
			if (Max < cnt) {
				w = i;
				Max = cnt;
			}
		}
		cnt = Max;
		for (ll i = n - 1; i > w; i--) {
			cnt -= a[i];
			Max = max(Max, cnt);
		}
		printf("%lld\n", Max);
	}
	return 0;
}