#include<iostream>
#include<cstdio>
typedef long long ll;
using namespace std;
const int N=200000;
ll arr[N+5],dp[N+5],ans;//now&&sum
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>arr[i];
for(int i=1;i<=n;i++)
{
if(dp[i-1]+arr[i]<0) dp[i]=0;
else dp[i]=dp[i-1]+arr[i];
ans=max(ans,dp[i]);
}
cout<<ans;
return 0;
}