#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int N;
	while(cin >> N && N > 0){
		cout << endl;
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N){
            int sum = 0;
            int maximum_i = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum_i = max(sum,maximum_i);
            }
            maximum = max(maximum,maximum_i);
		}
		cout << maximum;
	}
}