#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define in        []{int n; cin>>n; return n;}()

int main() {
    int N = in;
    if( !N ) return 0;
    vector<int> A(N+1, 0);
    rep( i, N ) A[i+1] = in + A[i];
    int ans = INT_MIN;
    rep( r, N+1 ) rep( l, r ) ans = max( ans, A[r] - A[l] );
    cout << ans << "\n";
    main();
}

