#include<iostream>
#include<algorithm>
#include<cstdio>
#define MAXN 50000
using namespace std;
int n;
long long a[MAXN],sum[MAXN];
/*
d[j]表示以j为终点的sum中最大的.
if(d[j]>0) d[j+1] = d[j]+a[j+1];
else
d[j+1] = a[j+1]
*/
int main()
{
cin>>n;
long long max = ;
//memset(a,0,sizeof(a));
for(int j=;j<n;j++)
{
cin>>a[j];
if(j==)
{
sum[] = a[];
continue;
}
if(sum[j-]>)
sum[j] = sum[j-] + a[j];
else
sum[j] = a[j];
if(sum[j]>max)
max = sum[j];
}
cout<<max<<endl;
return ;
}