#include<iostream>
using namespace std;

int main(){
    int n;
    while(cin>>n && n!=0){
       int* A=new int[n];
       int* S=new int[n+1];
       S[0]=0;
       for(int i=0;i<n;++i){
           cin>>A[i];
           if(i==0){
               S[i+1]=A[i];
           }
           else{
               S[i+1]=S[i]+A[i];
           }
       }

       int maxsum=0;
       for(int i=0;i<n+1;++i){
           for(int j=i;j<n+1;++j){
               maxsum=(S[j]-S[i]>maxsum?S[j]-S[i]:maxsum);
           }
       }

       cout<<maxsum<<"\n";
       delete[] A;
       delete[] S;
    }
}