#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <deque>
#include <set>
using namespace std;
#define speedup ios::sync_with_stdio(0),cin.tie(0);
long long int power(long long int n,long long int p)
{
long long int x=1;
for(int i=1;i<=p;i++)
{
x*=n;
}
return x;
}
template<typename t>
t gcd(t a,t b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
long long int maxSubArraySum(vector<long long int>&a)
{
int max_so_far = -10000000, max_ending_here = 0;
for (int i = 1; i < a.size(); i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
int main()
{
speedup;
int n;
long long int mx=(-10000000),h;
cin>>n;
vector<long long int>a(n+1);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<maxSubArraySum(a)<<endl;
return 0;
}
Copy