#include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a,i,maxm;
int main(){
  while(1){
    cin>>n;
    maxm=-999999999;
    if(n==0)break;
    cin>>a;
    dp[1]=maxm=a;
    for(int i=2;i<=n;i++){
      cin>>a;
      dp[i]=dp[i-1]+a;
      if(dp[i]<0)dp[i]=0;
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<endl;
  }
  return 0;
}