#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int n,tmp1,tmp2,maxn,head,tail,o,i,tmp;
int queue[200000];
int f[200000];
int a[200000];
int s[200000];
int main()
{
freopen("circlea.in","r",stdin);
freopen("circlea.out","w",stdout);
scanf("%d",&n);
s[0]=0;
for (i=1;i<=n;i++){
scanf("%d",&a[i]);
s[i]=s[i-1]+a[i];
}
o=s[n]/2;
if (s[n]%2!=0) o++;
memset(queue,0,sizeof(queue));
head=1;
tail=1;
queue[tail]=a[1];
maxn=0;
while (tail<=n){
tail++;
queue[tail]=queue[tail-1]+a[tail];
tmp1=queue[tail];
tmp2=s[n]-queue[tail];
tmp=tmp1<tmp2?tmp1:tmp2;
if (tmp>maxn) maxn=tmp;
while (queue[tail]>s[n]-queue[tail]){
queue[tail]-=a[head++];
tmp1=queue[tail];
tmp2=s[n]-queue[tail];
tmp=tmp1<tmp2?tmp1:tmp2;
if (tmp>maxn) maxn=tmp;
}
}
printf("%d",maxn);
return 0;
}