#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,i,j;
  cin >> n;
  while(n!=0) {
    long long sum[5001]={};
    int b;
    vector <long long> v;
    cin >> sum[1];
    for(i=2;i<=n;i++){
      cin >> b;
      sum[i]=sum[i-1]+b;
      //cout << sum[i] << endl;
    }
    
    for(i=0;i<=n;i++){
      for(j=i+1;j<=n;j++){
	v.push_back(sum[j]-sum[i]);
      }
    }
    sort(v.begin(),v.end());
    cout << v[v.size()-1] << endl;
    cin >> n;
  }
  return 0;
  
}