#include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int a[5000];
  int n;
  
  while( cin >> n )
    {
      int mv = -200000;
      
      if ( n == 0 )
        break;

      for ( int i = 0; i < n; ++i )
        {
          cin >> a[i];
        }

      unique_ptr<int[][5000]> c(new int[n][5000]);
      
      for ( int i = 0; i < n; ++i )
        {
          for ( int j = 0; j <= i; ++j )
            {
              if ( i == j )
                {
                  c[i][j] = a[i];
                }
              else
                {
                  c[i][j] = c[i - 1][j] + a[i];
                }
              mv = max( mv, c[i][j] );
            }
        }

      cout << mv << endl;
      
    }
  
  return 0;
}