#include <iostream>
#include <algorithm>
using namespace std;

int main(){
  int n, num, a, maxx;

  while(cin >> n){
    if(n==0) return 0;

    num = maxx = 0;

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

    cout << num << endl;
  }

  return 0;
}