#include <iostream>
using namespace std;

int main() {
 int n;
 int a[5000];
 int S[5000];
 while ((cin >> n) && n != 0) {
  for (int i=0; i<n; ++i) {
   cin >> a[i];
  }
  S[0] = 0;
  for (int i=0; i<n; ++i) {
   S[i+1] = S[i] + a[i];
  }
  int max = -100001;
  for (int i=0; i<n; ++i) {
   for (int j=i+1; j<=n; ++j) {
    max = (S[j]-S[i] > max) ? S[j]-S[i] : max;
   }
  }
  cout << max << endl;
 }
}
