#include<iostream>
#include<cstdio>
using namespace std;
long long n,num[100001],total[100001];
long long all,ans;
int main()
{
freopen("circlea.in","r",stdin);
freopen("circlea.out","w",stdout);
cin>>n;
int i;
for(i=1;i<=n;i++) {cin>>num[i];all+=num[i];}
int j=1,l=0;
for(i=1;i<=n;i++){
while(l+num[j]<=all-l-num[j]){
l+=num[j];
j++;
if(j>n)j=1;
}
if(ans<l) ans=l;
else if(ans<all-l-num[j]) ans=all-l-num[j];
l-=num[i];
}
cout<<ans<<endl;
return 0;
}