var
a:array[0..1010]of longint;
i,j,k,l,m,n,x,y,ans,now:longint;
xx,yy:boolean;
procedure restart;
begin
if n+1-i<6 then
begin
writeln(ans);
halt;
end;
x:=a[i]+a[i+2];
y:=a[i+1]+a[i+3];
i:=i+4;
now:=1;
xx:=true;
yy:=true;
if ((x>21)or(x<=y))and(y<=21) then ans:=ans+1;
if (y>21) or (x>21) or ((x<=y)and(y<=21)) then
if n+1-i>=6 then restart else
begin
writeln(ans);
close(input);close(output);
halt;
end;
end;
begin
assign(input,'jack.in');reset(input);
assign(output,'jack.out');rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
i:=1;
restart;
while i<=n do
begin
if x=21 then
begin
restart;
continue;
end;
if now=1 then
begin
if x<=16 then
begin
x:=x+a[i];
inc(i);
if yy then now:=2;
continue;
end;
if x+a[i]>21 then
begin
inc(i);
inc(ans);
restart;
continue;
end;
if yy then
begin
now:=2;
if x<=y then xx:=false;
continue;
end;
if not yy then
begin
if y>=x then
begin
inc(ans);
restart;
end
else
begin
if x+a[i]+a[i+1]>21 then
begin
i:=i+2;
inc(ans);
restart;
end;
end;
end;
end;
if now=2 then
begin
if y+a[i]<=21 then
begin
y:=y+a[i];
inc(i);
if x<=y then
begin
inc(ans);
restart;
continue;
end;
if xx then now:=1;
continue;
end;
yy:=false;
if xx then now:=1;
end;
end;
writeln(ans);
close(input);close(output);
end.