#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int a;
    cin >> a;
    int sum = a;
    int max_sum = sum;
    for (int i = 1; i < n; i++) {
      cin >> a;
      sum = max(sum + a, a);
      max_sum = max(max_sum, sum);
    }
    cout << max_sum << endl;
  }
}

