var
c,d,e,n,ans:longint;
a,b,q,daan:array[1..10000]of longint;
begin
assign(input,'maxxl.in');
assign(output,'maxxl.out');
reset(input);
rewrite(output);
read(n);
for c:=1 to n do
begin
read(a[c]);
for d:=1 to c do
if (a[d]<=a[c])and(b[d]>b[c]) then
begin
b[c]:=b[d];
q[c]:=d;
end;
inc(b[c]);
if ans<b[d] then
begin
ans:=b[d];e:=d;
end;
end;
writeln(ans);
c:=ans;
repeat
daan[c]:=a[e];
e:=q[e];
dec(c);
until e=0;
for c:=1 to ans do
write(daan[c],' ');
writeln;
close(input);close(output);
end.