#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  while(cin>>n,n){
    int sum = 0, maxs = 0, a[10000];
    REP(i,n)
      cin >> a[i];
    FOR(k,1,n){
    FOR(i,0,k){
      sum += a[i];
      maxs = max(sum, maxs);
    }
    FOR(i,0,k){
      sum -= a[i];
      maxs = max(sum, maxs);
    }
    }
    cout << maxs << endl;
  }
  return 0;
}