#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int n, x, max_;
  int dp[5001];
  while(1){
    cin >> n;
    if(!n) break;
    max_=0; dp[0]=0;
    for(int i=1; i<=n; ++i){
      cin >> x;
      dp[i] = max(x, dp[i-1]+x);
      max_ = max(max_, dp[i]);
    }
    cout << max_ << endl;
  }
  return 0;
}