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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n, a;
  while (true) {
    cin >> n;
    if (n == 0) return 0;
    vector<ll> dp(n, -INFL);
    cin >> dp[0];  // n番目に切った時の最大値
    for (int i = 0; i < n - 1; i++) {
      cin >> a;
      dp[i + 1] = max(dp[i] + a, a);
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
  }
}

