var
c,d,f,g,ans,n:longint;
a,b,e:array[0..1001]of longint;
begin
assign(input,'missile.in');
reset(input);
assign(output,'missile.out');
rewrite(output);
while not eof do
begin
inc(n);
read(a[n]);
if a[n]=0 then dec(n);
end;
for c:=1 to n do
begin
for d:=0 to c-1 do
if (a[d]>=a[c])and(b[d]>b[c]) then
b[c]:=b[d];
inc(b[c]);
if ans<b[c] then ans:=b[c];
end;
writeln(ans);
ans:=0;
repeat
inc(ans);
f:=0;
for c:=1 to n do
if (a[c]>=a[f])and(e[c]=0) then f:=c;
e[f]:=1;
repeat
g:=0;
for c:=f+1 to n do
if (a[c]>=a[g])and(e[c]=0) then g:=c;
e[g]:=1;
f:=g;
until a[f]=0;
g:=0;
for d:=1 to n do
if e[d]=0 then
begin
g:=1;break;
end;
if g=0 then break;
until 2=1;
writeln(ans);
close(input);close(output);
end.