#include <iostream>
#include <algorithm>
#define INF 1<<27
using namespace std;
int main(){
  int n;
  while(cin >> n,n) {
    int sum[5000] = {0},a[5000];
    for(int i = 0 ; i < n ; i++ ) {
      cin >> a[i];
      if(i == 0) sum[i] += a[i];
      else  sum[i] += a[i] + sum[i-1];

    }
    int mx = sum[0];
    for(int i = 0 ; i < n-1 ; i++ ){
      for(int j = i+1 ; j < n ; j++ ){
	mx = max(mx,max(sum[j] - sum[i],sum[j]));
      }
    }
    cout << mx << endl;
  }
  return 0;
}