#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int n;
  while(cin >> n, n) {
    int x[n];
    for (int i=0; i<n; i++)
      cin >> x[i];

    int ans = 0;
    int dp[n][n];               // dp[i][j] : iツつゥツづァjツづ慊づづ個和
    for (int i=0; i<n; i++) {
      dp[i][i] = x[i];
      ans = max(ans, dp[i][i]);
      for (int j=i+1; j<n; j++) {
        dp[i][j] = dp[i][j-1] + x[j];
        ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << endl;
  }
}