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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n,0);
        for(i=0; i<n; ++i){
            cin >> a[n];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(i=0; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + n[i];
            } else {
                dp[i] = n[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}