//
#include <iostream>
using namespace std;
int main()
{
  int n;
  while(true){
    int a[5000] = {0};
  cin >> n;
  if (n == 0 ) break;
  for (int i = 0; i < n;i++)
    cin >> a[i];
  int sum_max = a[0];
  int sum = 0;
  for (int i = 0; i <n;i++){
    for (int j = i; j < n; j++){
      sum += a[j];    if(sum > sum_max) sum_max = sum;
    }
    int sum = 0;
  }

  }
  cout << sum_max;
    

  }
}