#include <cstdio>

using namespace std;

int n, a[5000];

int main()
{
    while( 1 )
    {
        scanf( "%d", &n );
        if( n == 0 ) break;
        int index = -1000000000;
        for( int i = 0; i < n; i++ )
        {
            scanf( "%d", &a[i] );
        }

        int l = 0;
        while( l < n )
        {
            int r = l + 1;
            while( r < n )
            {
                int sum = 0;
                for( int i = l; i <= r; i++ )
                {
                    sum += a[i];
                }
                if( index < sum )
                {
                    index = sum;
                }
                r++;
            }
            l++;
        }
        printf( "%d\n", index );

    }
    return 0;

}
