program ex;
var f,data:array[0..1000] of longint;
n,i,j,k,ans,biao,tt,sum1,sum2:longint;
begin
assign(input,'jack.in');
assign(output,'jack.out');
reset(input);
rewrite(output);
read(n);
for i:=1 to n do
read(data[i]);
fillchar(f,sizeof(f),255);
f[0]:=0;
for i:=1 to n-5 do
if f[i-1]<>-1 then
for j:=0 to 21 do
begin
tt:=0;
biao:=i+4;
sum1:=data[i]+data[i+2];
sum2:=data[i+1]+data[i+3];
while (sum1<=16)or(j>tt) do
begin
if (sum1>21) or(sum2>21) then break;
if sum1<=16 then
begin
sum1:=sum1+data[biao]; inc(biao); if biao>n then break; end;
if tt<j then begin sum2:=sum2+data[biao];
inc(tt); inc(biao); if biao>n then break; end;
end;
if (sum1>=sum2) and(sum1<=21) then f[i+biao-2]:=f[i-1]
else f[i+biao-2]:=f[i-1]+1;
end;
for i:=n-4 to n do
if f[i]>ans then ans:=f[i];
write(ans);
close(input); close(output);
end.