var a:array[1..1000] of longint;
n,i,j,ans,x1,x2:longint;
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:=0;
while i>n-5 do
x1:=0; x2:=0;
inc(i); x1:=a[i]; inc(i); x2:=a[i];
inc(i); x1:=x1+a[i]; inc(i); x2:=x2+a[i];
while ((x1<=21)and(x2<=21)) do
begin
if x1<=16 then inc(i); x1:=x1+a[i];
if ((x1>x2)and(x1<21)) then begin inc(i); x2:=x2+a[i];
end;
if x1>21 then inc(ans);
if ((x1<x2) and (x2<=21)) then inc(ans);
end;
writeln(ans);
close(output);
end.