#include <iostream>

int main(){
  int n, num;

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

    num = 0;

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

    cout << num << endl;
  }

  return 0;
}