#include <iostream>
using namespace std;

#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  long long ans, acc[5001];
  int n;
  
  while (cin >> n){
    if (n==0) break;
    acc[0] = 0;
    for (int i=0; i<n; i++){
      int t;
      cin >> t;
      acc[i+1] = t + acc[i];
    }
    ans = -(1<<31-1);
    for (int i=0; i<n; i++){
      for (int j=0; j<=i; j++){
        int sum = acc[i+1] - acc[j];
        ans = MAX(ans, sum);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
