#include <iostream>
#include <vector>

using namespace std;

int findMax(vector<int>& a) {
  int r = 0, sum, max;
  for (int i = 0, max = 0; i < a.size(); i++) {
    for (int j = i, sum = 0; j < a.size(); j++) {
      sum += a[j];
      if (max < sum) max = sum;
    }
    if (max > r) r = max;
  }
  return r;
}

int main() {
  int n, t;
  while (1) {
    cin >> n;
    if (n == 0) break;

    vector<int> a;
    for (int i = 0; i < n; i++) {
      cin >> t;
      a.push_back(t);
    }
    cout << findMax(a) << endl;
  }
  return 0;
}