#include<iostream>
#include<string.h>
using namespace std;

const int N = 1e6 + 10;

int arr[N];
int f[N];
int main(void)
{
	int n;
	while(cin >> n)
	{
		memset(f,0,sizeof(f));
		memset(arr,0,sizeof(arr));
		for(int i = 1;i <= n;i++) cin >> arr[i];
		
		for(int i = 1;i <= n;i++)
		{
		   f[i] = max(f[i - 1] + arr[i], arr[i]);
		}
		int res = -0x3f3f3f3f;
		for(int i = 1;i <= n;i++)
		{
			res = max(res,f[i]); 
		}
		cout << res << endl;
	}

	return 0;
}