#include<bits/stdc++.h>
const long long maxn=125535;
inline const void read(long long &a)
{
char c=getchar();long long b=1;a=0;
while(c<'0'||c>'9'){if(c=='-')b=-1;c=getchar();}
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
a*=b;
}
long long n,answer=0,a[maxn];
long long sum[maxn],ans[maxn],small=0,ansl=0,ansr=0,res=-INT_MAX;
int main()
{
ans[0]=sum[0]=0;
read(n);
for(long long i=1;i<=n;i++)
{
read(a[i]);sum[i]=a[i];
sum[i]+=sum[i-1];
ans[i]=sum[i]-ans[small];
if(ans[i]>res){ansl=small;ansr=i;res=ans[i];}
if(sum[i]<sum[small])small=i;
}
answer=res;
small=0;res=-INT_MAX;ans[0]=sum[0]=0;
for(long long i=ansl+1;i<=ansr;i++)a[i]=-INT_MAX;
for(long long i=1;i<=n;i++)
{
sum[i]=a[i];
sum[i]+=sum[i-1];
ans[i]=sum[i]-ans[small];
if(ans[i]>res)res=ans[i];
if(sum[i]<sum[small])small=i;
}
if(res>=0)answer+=res;
std::cout<<answer;
return 0;
}