#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int a[5000], n, ans, sum;
    
    while(true)
    {
        cin >> n;
        if(n == 0) break;
        rep(i,n)
            cin >> a[i];
        
        ans = a[0];
        rep(i,n)
        {
            sum = 0;
            for(int j=i; j<n; j++)
            {
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}