#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

int main() {
    int n;

    while (cin >> n, n) {
        vector<ll> a(n);
        rep(i, n) cin >> a[i];

        ll ans = -1e18, cur = 0;
        rep(i, n) {
            cur = max(cur + a[i], a[i]);
            ans = max(ans, cur);
        }
        cout << ans << endl;
    }

    return 0;
}
