#include <iostream>
using namespace std;

int main(){
  int n ,hoge ,total=0 ,max=0;
  while( true ){
    cin >> n;
    if( !n ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){
      cin >> hoge;
      total += hoge;
      if( total < 0 ) total = 0;
      if( total > max ) max = total;
    }
    cout << max << endl;
    total = 0;
    max = 0;
  }
}