#include<iostream>
using namespace std;
int main(){
	long int n, m[5000] = { 0 }, max = -2147483647, temp = 0;
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}for (int i = n - 1; i >= 0; i--){
			temp = m[i];
			for (int l = i-1; l >= 0; l--){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max = -2147483647;
	}
	return 0;
}