#include <iostream>
#include <algorithm>
#define N 5000000
using namespace std;

int main(){
  int n, num, a, maxx;
  int ans[N], ac;
  ac = 0;

  while(cin >> n){
    if(n==0){
      ans[ac] = 0;
      break;
    }

    num = maxx = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }
    ans[ac] = maxx;
    ac++;
  }

  for(int i=0;ans[i]!=0;i++)
    cout << ans[i] << endl;

  return 0;
}