#include<iostream>

using namespace std;


int main()
{
	int n,tmp1,tmp0;
	int arr[5001] = {0};
	int sum[5001] = { 0 };
	
	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}

		sum[0] = arr[0];
		int j = 0;
		for (int i = 1; i < n; i++) {
			tmp0 = arr[i - 1];
			tmp1 = arr[i];
			if (tmp1 * tmp0 > 0) {
				if (tmp1 > 0) {
					sum[j] += tmp1;
				}
				else {
					if (sum[j] > 0) {
						sum[j] += tmp1;
					}
					else {
						if (tmp1 > tmp0) {
							sum[j] = tmp1;
						}
					}		
				}	
			}
			else {
				++j;
				if (sum[j-1] > 0) {
					sum[j] = sum[j-1] + tmp1;
				}
				else {
					sum[j] = tmp1;
				}
			}
			//cout << "sum[" << j << "]=" << sum[j] << endl;
		}

		/*for (int i = 0; i <= j; i++) {
			cout << sum[i] << ends;
		}
		cout << endl;*/

		int max = sum[0];
		for (int i = 1; i <= j; i++) {
			if (sum[i] > max) {
				max = sum[i];
			}
		}
		cout << max << endl;
		
	}

	return 0;
}
