#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
	int sum[5001];
	int n;

	while( cin >> n && n != 0 ){
		int input;
		for( int i = 0;i < 5001;i++ ) sum[i] = 0;
		cin >> input;
		sum[1] = input;
		for( int i = 2;i <= n;i++ ){
			cin >> input;
			sum[i] = input + sum[i - 1];
		}

		int answer = -10000000;

		for( int i = 1;i <= n;i++ ){
			for( int j = 0;j < i;j++ ){
				answer = max( answer, sum[i] - sum[j] );
			}
		}

		cout << answer << endl;
	}

			

	return 0;
}