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