#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax2(5010,0);
        int temp = 0;
        REP(i,number)
        cin >> a[i];
        for(int j = 0; j<number;j++)
            for(int k = j;k<number;k++)
            {
                for(int l = k;l<number;l++)
                {
                    if(k == l)
                        tempmax2[k] = a[k];
                    else{
                        
                        tempmax2[k] += a[l];
                    }
                    if(temp <= tempmax2[k])
                        temp = tempmax2[k];
                }
            
            }
        //sort(tempmax.begin(),tempmax.end(),greater<int>());
        //sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        //if(tempmax[0]>temp)
            //answer[l] = tempmax[0];
        //else
        // answer[l] = temp;
        printf("%d\n",temp);
        temp = 0;
    }
    return 0;
}