#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<int> a;
    a.resize(n+1);
    a[0]=0;
    REP(i,n) cin >> a[i+1];
    REP(i,n) a[i+1]+=a[i];
    int answer=-1048576;
    REP(i,n)REP(j,i) answer=max(answer,a[i]-a[j]);
    cout << answer << endl;
  }
}