{*******************************************}
{* Program Name: Maxxl *}
{* Input File: maxxl.in *}
{* Output File: maxxl.out *}
{* Date: 2008.7.24 *}
{* Programmer: Peng Bo *}
{*******************************************}
program maxxl;
type
jl=record
x,y,z:word;
end;
sz=array[0..10000]of jl;
var
s:sz;
n,g:word;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure input;
var
f:text;
i:word;
begin
assign(f,'maxxl.in');
reset(f);
readln(f,n);
for i:=1 to n do
begin
readln(f,s[i].x);
s[i].y:=1;
s[i].z:=0;
end;
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure output;
var
f:text;
begin
assign(f,'maxxl.out');
rewrite(f);
writeln(f,s[g].y);
while g<>0 do
begin
write(f,s[g].x);
g:=s[g].z;
if g<>0
then
write(f,' ');
end;
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main;
var
j,k,m:word;
begin
for j:=(n-1) downto 1 do
begin
m:=0;
for k:=(j+1) to n do
if (s[k].x>=s[j].x)and(s[k].y>m)
then
begin
m:=s[k].y;
s[j].z:=k;
end;
if (m<>0)or(s[j].y>m)
then
begin
s[j].y:=m+s[j].y;
if s[j].y>=s[g].y
then
g:=j;
end;
end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
input;
g:=n;
main;
output;
end.