#include <cstdio>
#include <algorithm>

using namespace std;

int ret = 0, a[5000], n;

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

        int l = 0;
        while( l < n )
        {
            int r = l , sum = 0;
            while( r < n )
            {
                sum += a[r];
                ret = max( ret, sum );
                r++;
            }
            l++;
        }
        printf( "%d\n", ret );
    }

    return 0;
}
