#include <iostream>
#include <algorithm>

using namespace std;

int main(void){

  while(1){

    int n;
    cin >> n;
    if( n == 0 ) break;
    
    int N[5000];
    for( int i = 0 ; i < n ; i++ ){
      cin >> N[i];
    }
   
    int sum = 0;
    int l = -9999999;
    for( int i = 0 ; i < n ; i++ ){
      if( sum + N[i] >= N[i] ){
	sum += N[i];
      }
      if( sum > l ){
	l = sum;
      }
    } 
    cout << l << endl;
  }
  return 0;
}