#include <iostream>
#include <vector>
using namespace std;

int main(void)
{
	vector<int> numbers;
	int count, tmp, ans, Max;

	while (cin >> count) {
		ans = 0;
		Max = 0;
		for (int i = 0; i < count; i++) {
			cin >> tmp;
			if (tmp + ans > 0) {
				ans += tmp;
				Max = max(Max, ans);
			}else {
				ans = 0;
			}
			numbers.push_back(tmp);
		}
		cout << Max << endl;
	}
	
	return 0;
}