var
a:array[1..6] of integer;
b:array[1..1000] of integer;
n,i,q,m,kk,u,j,o,aa:integer;
begin
readln(n);
for i:=1 to n do readln(b[i]);
i:=0; a[1]:=1; a[2]:=3; a[3]:=7; a[4]:=30; a[5]:=120; a[6]:=365;
q:=0; m:=0; kk:=0; u:=0;
repeat
inc(i);
if (b[i]=1)and(u=0) then
begin
inc(q);
for j:=1 to 6 do
if q=a[j] then begin m:=m+j; break; end;
end;
if b[i]=0 then
begin
inc(kk);
u:=1;
end;
if (b[i]=1)and(u=1) then
begin
kk:=kk-1; inc(q);
if kk=0 then begin
q:=q-1;
for j:=1 to 6 do
if q=a[j] then begin m:=m+j; break; end;
end else
begin
aa:=1;
for o:=1 to kk do
aa:=aa*2;
if q<=aa then q:=1 else q:=q-aa;
for j:=1 to 6 do
if q=a[j] then begin m:=m+j; break; end;
end;
u:=0;
kk:=0;
end;
until i=n;
writeln(m);
end.
样例应该输出12,运行后输出5。。