#include <algorithm>
#include <iostream>
#include <limits>
using namespace std;
int main() {
  int n;
  while (cin >> n && n) {
    int m = numeric_limits<int>::min();
    int s = 0;
    while (n--) {
      int k;
      cin >> k;
      s += k;
      m = max(m, s);
      if (s < 0) s = 0;
    }
    cout << m << endl;
  }
}