#include <iostream>

using namespace std;

int A[50000]={0};
int S[50000]={0};

int main(){
  int n;

  while(cin>>n&&n>0){
    for(int i=0;i<n;++i) cin >> A[i];
    
    long maxsum = -1000000;
    int prefix_sum[50002]={0};
    prefix_sum[0] = 0;
    for(int i=1;i<n+2;++i){
      prefix_sum[i]=prefix_sum[i-1]+A[i-1];
    }
    for(int i=0;i<n+2;++i){
      for(int j=i;j<n+2;++j){
        if(prefix_sum[j]-prefix_sum[i]>maxsum){
          maxsum = prefix_sum[j]-prefix_sum[i];
        }
      }
    }
    cout << maxsum << endl;
  }

  return 0;
}