include <bits/stdc++.h>
using namespace std;
const int maxn=200005,minn=-0x3f3f3f3f;
int n,arr[maxn];
int maxSubSum(int le, int ri)
{
if(le == ri)
{
return arr[le];
}
int mid=(le+ri) >> 1,leftSum = minn,rightSum = minn,sum = 0;
for(int i=mid;i>=le;i--)
{
sum += arr[i];
if(sum > leftSum)
{
leftSum = sum;
}
}
sum = 0;
for(int i = mid+1;i <= ri;i++)
{
sum += arr[i];
if(sum > rightSum) rightSum=sum;
}
int t = max(maxSubSum(le,mid),maxSubSum(mid+1,ri));
return max(t,leftSum + rightSum);
}
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i++)
{
scanf("%d",&arr[i]);
}
printf("%d\n",maxSubSum(1,n));
return 0;
}