#include<iostream>
#define INFTY (1<<21)
using namespace std;

void maxsequence(int n) {
    int a[n], s[n], result = -INFTY;
    for ( int i = 0; i < n; i++ ) cin >> a[i];
    s[0] = a[0];
    for ( int i = 1; i < n; i++ ) s[i] = max(a[i], a[i] + s[i - 1]);
    for ( int i = 0; i < n; i++ ) result = max(result, s[i]);
    cout << result << endl;
}

int main() {
  int n;
  while ( cin >> n ) {
      if ( n == 0 ) return 0;
      maxsequence(n);
  }
}
