#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	
	int n = 1;
	std::cin >> n;


	while (n)
	{
		std::vector<int32_t> num_list{};

		while (n--)
		{
			int tmp = 0;
			std::cin >> tmp;
			num_list.push_back(tmp);
		}

		std::vector<int32_t> comfarm_list{};
		std::vector<int32_t> sum_list{};
		for( auto num : num_list )
		{
			for (auto& sum : sum_list)
			{
				if (num < 0)
				{
					comfarm_list.push_back(sum);
				}
				sum += num;
			}
			sum_list.push_back(num);
		}

		for (auto sum : sum_list)
		{
			comfarm_list.push_back(sum);
		}

		int32_t max_sum = *( std::max_element(comfarm_list.begin(),comfarm_list.end()) );
		std::cout << max_sum << std::endl;
	
		std::cin >> n;
	}

	return 0;
}
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int do_stuff(int n)
{
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int max_so_far = 0;
    int max_ending_here = 0;

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        max_ending_here = max(max_ending_here + curr, 0);
        max_so_far = max(max_so_far, max_ending_here);
    }

    if (max_so_far == 0) {
        max_so_far = *max_element(a.begin(), a.end());
    }
    return max_so_far;
}

int main(int argc, char* argv[])
{
    //freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    while (n != 0) {
        int ans = do_stuff(n);
        printf("%d\n", ans);
        scanf("%d", &n);
    }
    return 0;
}