#include <iostream>
#include <cstdlib>
#include <climits>
using namespace std;
const static int L_MAX = 5001;

int main() {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }

    int seq[ L_MAX ];
    int sum[ L_MAX ];
    int maxv = INT_MIN;
    int minvInSum = 0;
    seq[ 0 ] = 0;
    sum[ 0 ] = 0;

    for( int i = 1; i <= n; i++ ) {
      cin >> seq[ i ];
      sum[ i ] = sum[ i - 1 ] + seq[ i ];
      minvInSum = min( minvInSum, sum[ i ] );
      maxv = max( maxv, sum[ i ] - minvInSum );
    }
    cout << maxv << endl;
  }
}