//48
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=-1<<30,seq=-1<<30;
    while(n--){
      int i;
      cin>>i;
      seq=max(seq+i,i);
      ans=max(ans,seq);
    }
    cout<<ans<<endl;
  }
  return 0;
}