#include <cstdio>
#include <algorithm>

using namespace std;

int N,K[5001],T;

int main()
{
        scanf("%d",&N);
        if (N == 0) return 0;

        T = 0;

        for (int i=1;i<=N;i++){
                scanf("%d",K+i);
        }

        for (int i=1;i<=N;i++) {
                K[i] += K[i-1];
        }

        for (int i=0;i<=N;i++) {
                for (int j=i;j<=N;j++) {
                        T = max(T,K[j]-K[i]);
                }
        }

        printf("%d\n",T);

        main(); 
}