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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n = 0;
	std::vector<int> a;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

	for(;;){
#if INPUT_FROM_FILE
		ifs >> n;
#else
		std::cin >> n;
#endif
		if(n == 0){ break; }

		a.resize(n);
		for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
			ifs >> a[i];
#else
			std::cin >> a[i];
#endif
		}

		long max_sum = -1000000000;

		for(int i = 0; i < n; i++){
			long sum = a[i];
			if(max_sum < sum){
				max_sum = sum;
			}
			for(int j = i + 1; j < n; j++){
				sum += a[j];
				if(max_sum < sum){
					max_sum = sum;
				}
			}
		}

		std::cout << max_sum << std::endl;
	}

	return 0;
}
