#include<iostream>
using namespace std;

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        int max = 0, max2 = -1000000;
        int sum = 0;
        int a[n];
        for( int i = 0; i < n; i++ )
        {    
            cin >> a[i];

            if( a[i] > 0 )
            {
                sum += a[i];
                if( max < sum )
                    max = sum;
            }
            else
            {
                if( sum + a[i] > 0 )
                    sum += a[i];
                else
                    sum = 0;
            }
            
            if( max2 < a[i] )           //全てが負の値だった時に、その中でも最大の値を格納。
                max2 = a[i];
        }
        if( max == 0 )
            cout << max2 << endl;
        else
            cout << max << endl;
    }
    return 0;
}
