#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int n;
int a[50000];
int S[50000];


int main(){

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

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

  int max = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int k = 0; k < i; ++k)
    {
      if(S[i] - S[k] > max) max = S[i] - S[k];
    }
  }

  cout << max << endl;

  }
}