#include<iostream>
#include<cstdio>
#include<string>
#include<cfloat>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
const int mod = 1e9+7;
const int INFINT = INT_MAX/2;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    int n;
    cin >> n;
    while(n!=0){
        int a[n];
        REP(i, n){
            cin >> a[i];
        }
        int maxSum = a[0];
        int res = -INFINT;
        for (int i=1;i<n;i++){
            if(maxSum + a[i] < a[i]){
                maxSum = a[i];
            }else{
                maxSum += a[i];
            }
            res = max(res, maxSum);
        }
        cout << res << endl;
        cin >> n;
    }
    return 0;
}