#include <bits/stdc++.h>
using namespace std;


int main(){
  int n; 
  while(true){
    cin >> n;
    if(n == 0) break;

    vector<int64_t> a(5010), sum(5010, 0); 
    for(int i=1; i<=n; i++){
      cin >> a[i];
      sum[i] = sum[i-1] + a[i];
    }

    int64_t ans = -99999999;
    for(int i=0; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        ans = max(ans, sum[j]-sum[i]);
      }
    }
    cout << ans << endl;
  }
}
  
  
