program savey;
var
n,i,l,ans:longint;
sz:array[1..1000]of char;
function find(a:longint):longint;
var
t,i:longint;
begin
if a=1 then begin
find:=1;
if sz[1]='0' then sz[1]:='1' else sz[1]:='0';
end
else begin
t:=0;
if sz[a-1]<>'1' then t:=t+find(a-1);
for i:=a-2 downto 1 do
if sz[i]<>'0' then t:=t+find(i);
if sz[a]='0' then sz[a]:='1' else sz[a]:='0';
t:=t+1;
find:=t;
end;
end;
begin
assign(input,'savey.in');
assign(output,'savey.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
read(sz[i]);
l:=0;
for i:=n downto 1 do
if sz[i]='1' then begin
l:=i;
break;
end;
ans:=0;
for i:=l downto 1 do
if sz[i]='1' then ans:=ans+find(i);
writeln(ans);
close(input);
close(output);
end.