
[pascal]
program p497(input,output);
type
sss=array[1..2000] of integer;
var
a,b,h,x:sss;
i,j,max1,max2,max,n,s,k:integer;
procedure work;
begin
n:=n+1;
readln(h[n]);
b[n]:=0;
max1:=0;max2:=0;
for i:=1 to n-1 do
if (a>max1) and (h[n]>h) then
begin
max1:=a;
max2:=i;
end;
a[n]:=max1+1;
b[n]:=max2;
if a[n]>max then
begin
max:=a[n];
s:=n;
end;
end;
procedure out;
begin
writeln('Max hits: ',max);
j:=1;
x[1]:=s;
i:=b[s];
while(i>0) do
begin
j:=j+1;
x[j]:=i;
i:=b;
end;
writeln('Max hits: ',max);
for i:=j downto 1 do writeln(h[x]);
end;
Begin
max:=0;n:=0;
while not eof(input) do work;
out;
end.
[/pascal]