#include <fstream>
#include <vector>
#include <stdint.h>

using namespace std;

long long FindMax(vector <long long> &a, unsigned int &n)
{
	long long max = INT32_MIN;
	long long total = 0;
	for (unsigned int i = 0; i < n; i++)
	{
		total += a[i];
		if (total > max)
		{
			max = total;
		}
		if (total < 0)
		{
			total = 0;
		}
	}
	return max;
}

int main()
{
	ifstream input("DCONMAX.inp");
	ofstream output("DCONMAX.out");
	
	unsigned int n;
	input >> n;
	vector <long long> a(n);
	for (unsigned int i = 0; i < n; i++)
	{
		input >> a[i];
	}
	output << FindMax(a, n);

	input.close();
	output.close();
	return 0;
}