#include <iostream>
#define TYPE long int
using namespace std;

int main(){
  int n;
  TYPE a[5010], s[5010];
  while(cin>>n && n){
    for( int i=1;i<=n;i++ )
      cin >> a[i];

    TYPE mx = a[1];
    for( int i=1;i<=n;i++ ){
      s[i] = a[i];
      mx = max(mx, s[i]);
      for( int j=i+1;j<=n;j++ ){
	s[j] = s[j-1] + a[j];
	mx = max(mx, s[j]);
      }
    }

    cout << mx << endl;
  }
  return 0;
}