#include<iostream>
using namespace std;
bool same(int a,int b){
  if(a*b>=0) return true;
  return false;
}
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int d;
    int s[n];
    int count = 0,begin = 0;
    int ans = -100000000;
    for(int i=0;i<n;i++){
      cin >> d;
      if(i==0) s[0] = d;
      else if(same(d,s[count])) s[count] += d;
      //cout << same(d,s[count]) << endl;
      else{
	count++;
	s[count] = d;
      }     
    }
    //for(int i=0;i<=count;i++) cout << s[i] << endl;
    if(s[0]<0) begin = 1;
    for(int i=begin;i<=count;i+=2){
      int h = s[i];
      if(ans<h) ans = h;
      for(int j=i+1;j<=count;j++){
	h += s[j];
	if(ans<h) ans = h;
      }
    }
    cout << ans << endl;
  }
  return 0;
}