#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main_(void)
{
	int n, a[5001];
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int goukei = 0, ryuta = -10000000;
	for (int i = 1; i <= n; i++)
	{
		goukei = 0;
		for (int j = 1; j <= n; j++)
		{
			goukei = goukei+a[j];
			ryuta = max(goukei, ryuta);
		}
	}
	cout << ryuta << endl;
	return 0;
}