#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	for (; ;)
	{
		int n;
		cin >> n;

		if (n == 0)
		{
			break;
		}

		vector<int> a(n);
		for (int i = 0; i < n; i++)
		{
			cin >> a.at(i);
		}

		int maxv = 0;
		for (int i = 0; i <= n; i++)
		{
			
			for (int j = 0; j < n; j++)
			{
				int sum = a.at(j);
				for (int k = j + 1; k < i; k++)
				{
					sum += a.at(k);
				}
				maxv = max(maxv, sum);
			}
		}

		cout << maxv << endl;
	}
}
