#include<iostream>

using namespace std;

int main(){
	int n;	
	while (true) {
		cin >> n;
		if (n != 0) {
			int *num = new int[n];
			for (int i = 0; i < n; i++) {
				cin >> num[i];
			}
			/*最大を更新していきたい*/
			int max_v = -999999999;
			for (int i = 0; i < n; i++) {
				int j = i, tmp_total = 0;
				for (j; j < n; j++) {
					tmp_total += num[j];
					if (tmp_total > max_v) {
						max_v = tmp_total;
					}

				}
			}
			cout << max_v << endl;

		}
		else if(n==0){
			break;
		}

	}
	return 0;
}
