#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;


int ans;
int d[5000];
int di;


int dfs(int n, int v)
{
  if(n < 0)
    return v;
  return max(v, dfs(n - 1, v + d[n]));
}


int main()
{
  while(true)
  {
    int n;
    ans = 0;
    di = 0;
    cin >> n;
    if(!n)
      break;
    for(int i = 0; i < 5000; i++)
      d[i] = 0;
    for(int i = 0; i < n; i++)
    {
      int x;
      cin >> x;
      if((x > 0 && d[di] < 0) || (x < 0 && d[di] > 0))
      {
        di++;
      }
      d[di] += x;
    }
    for(int i = 0; i <= di; i++)
    {
      ans = max(ans, dfs(i, 0));
    }
  
    cout << ans << endl;
  }
  return 0;
}