Var
i,j,k,n,m,l,r,s,t,x,y,ans,sum:longint;
a:array[1..201000]of longint;
Procedure Pin;
var
i,j,k:longint;
begin
read(n);
sum:=0;
for i:=1 to n do
begin
read(a[i]);
a[i+n]:=a[i];
sum:=sum+a[i];
end;
end;
Procedure Main;
var
i,j,k:longint;
begin
r:=1;
s:=a[1];
for l:=1 to 2*n-1 do
begin
repeat
r:=r+1;
s:=s+a[r];
until (s>sum/2)or(r=2*n-1);
s:=s-a[r];
dec(r);
if (ans<s )and(s<=sum/2) then
ans:=s;
s:=s-a[l];
end;
end;
begin
assign(input,'circlea.in');
assign(output,'circlea.out');
reset(input); rewrite(output);
pin;
main;
writeln(ans);
close(input);
close(output);
end.