#include <iostream>
using namespace std;

int main(){
        int n,a[5010];
        while(cin>>n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                long max = 0;
                for(int k = 0; k < n; k++){
                        long sum = 0;
                        for(int i=0; i<n-k; i++){
                                sum += a[i];
                                max = (max>sum)? max:sum;
                        }
                        for(int i=0; i<=k; i++){
                                sum += (a[n-k+i]-a[i]);
                                max = (max>sum)? max:sum;
                        }
                }
                cout << max << endl;
        }

}