#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<int> a;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
    }
    for(int i=1; i<=n; i++) a[i]+=a[i-1];
    int m = 0,M = a[0],ans = a[0];
    for(int i=0; i<n; i++){
      M = max(M,a[i]);
      ans = max(ans,M-m);
      m = min(m,a[i]);
    }
    cout <<ans<<endl;
  }
  return 0;
}