#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main () {
  int n;
  while( 1 ){
    cin >> n;
    if( !n ){ return EXIT_SUCCESS; }
    vector<int> v;
    v.reserve( n );
    for( int i = 0; i < n; i++ ) {
      cin >> v[ i ];
    }
    int summax = v[ 0 ];
    for( int i = 0; i < n; i++ ) {
      int sum = v[ i ];
      for( int j = i + 1; j < n; j++ ) {
         sum = sum + v[ j ];
         if( sum > summax ) {
           summax = sum;
         }
      }
    }
    cout << summax << endl;
  } 
}