#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int s, m = 0, r;
    cin >> r;
    s = r;
    for (int i = 1; i < n; i++) {
      int x;
      cin >> x;
      s += x;
      if (s < m)
        m = s;
      else
        r = max(r, s-m);
    }
    cout << r << endl;
  }
}