#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        int a[n];
        rep(i, n) cin >> a[i];
        int m = a[0], sum = a[0];
        for (int i = 1; i < n; i++)
        {
            sum = max(sum + a[i], a[i]);
            if (sum > m)
                m = sum;
        }

        OP(m)
    }

    return 0;
}
