program sas;
var
a:array[1..2001]of longint;
i,j,k,m,n,max:longint;
s:boolean;
procedure ff(x,y,z:longint);
var i,j:integer;
begin
j:=0;
writeln(y);
if x>=n then
if max<z then max:=z;
if x<n then
begin
if s=true then
for i:=1 to y do
begin
j:=j+a[x+i-1];
ff(x+i,2*y,z+j);
end;
if s=false then
for i:=1 to y do
ff(x+i,2*y,z);
end;
if s=true then s:=false else s:=true;
end;
begin
assign(input,'xoinc.in');
reset(input);
assign(output,'xoinc.out');
rewrite(output);
readln(n);
for i:=1 to n do
read(a[i]);
k:=a[1];
s:=false;
ff(1,1,0);
writeln(max);
end.