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

int main()
{
	int data_count = 0;
	while ((std::cin >> data_count) && (data_count > 0)) {
		std::vector<long> dataset;
		for (int i = 0; i < data_count; ++i) {
			int data = 0;
			std::cin >> data;
			dataset.push_back(data);
		}

		long max_sum = dataset[0];
		for (int i = 0; i < data_count - 1; ++i) {
			for (int j = i + 1; j < data_count; ++j) {
				max_sum = std::max(
					max_sum,
					std::accumulate(dataset.begin() + i, dataset.begin() + j, 0L));
			}
		}
		std::cout << max_sum << std::endl;
	}

	return 0;
}