#include <iostream>
#include <algorithm>

using namespace std;

typedef long long int ll;
int main() {
  int N;
  while (cin >> N) {
    if (N == 0) break;
    int num[5000];
    ll m = 0;
    for (int i = 0; i < N; i++) {
      cin >> num[i];
    }
    for (int i = 0; i < N; i++) {
      ll sum = 0;
      for (int j = i; j < N; j++) {
        sum += num[j];
        m = max(m, sum);
      }
    }
    cout << m << endl;
  }

  return 0;
}