#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 50//00
#define MIN -100001
#define _MAX 100
#define ABC 26
int main(void)
{
	int n, a, sum1 = MIN, sum2 = 0, sum3 = 0;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; ++i) {
			scanf_s("%d", &a);
			if (sum1 + a < a) {
				sum1 = a;
				sum2 = a;
			}
			else {
				if (sum1 + a < sum1 || sum2 != sum1) {
					sum2 += a;
				}
				else if (sum1 == sum2) {
					sum1 += a;
					sum2 = sum1;
				}
				if (sum2 > sum1) {
					sum1 = sum2;
				}
			}
		}
		printf("\n%d\n\n", sum1);
		sum1 = sum2 = MIN;
	}
}