#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;


int main(){
    int n;
    while(1){
        cin>>n;
        if(n==0)break;
        int dp[5000][5000]={};
        int a[5000]={};

        rep(i,5000)rep(j,5000)dp[i][j]=-INF;
        
        rep(i,n){
            cin>>a[i];
        }
        rep(i,n) dp[i][i]=a[i];
        
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                dp[i][j]=dp[i][j-1]+a[j];
            }
        }
        int maxi=-INF;
        rep(i,n){
            rep(j,n){
                maxi=max(maxi,dp[i][j]);
            }
        }
        cout<<maxi<<endl;
        
    }
    return 0;
}