program twolink;
type tree=^node;
node=record
data:integer;
lchild,rchild:tree;
end;
var
bt:tree;
n,m,i,ans:integer;
procedure creat(var btx:tree;nx:integer);
var
s:tree;
begin
new(s);
s^.data:=nx;
s^.lchild:=nil;
s^.rchild:=nil;
if btx=nil then begin btx:=s;ans:=ans+1; end
else
if s^.data<btx^.data then creat(btx^.lchild,nx)
else
if s^.data>btx^.data then creat(btx^.rchild,nx);
end;
procedure print(btx:tree);
begin
if btx<>nil then
begin
print(btx^.lchild);
write(btx^.data,' ');
print(btx^.rchild);
end;
end;
begin
assign(input,'random.in');
reset(input);
assign(output,'random.out');
rewrite(output);
bt:=nil;
readln(n);
for i:=1 to n do
begin
read(m);
creat(bt,m);
end;
writeln(ans);
print(bt);
close(input);
close(output);
end.