type tree = ^p;
p =
record
n:T;
left:tree;
right:tree;
end;

procedure root (var a:tree; var inf:TF);
begin
 new(a);
 read(a^.n,inf);
 a^.left:=nil;
 a^.right:=nil;
end;

procedure addleaf(var a:tree, n:T);
begin
if a<>nil then
begin
 if n>=a^.n then addleaf(a^.right,n)
 else addleaf(a^.left,n)
end
else
begin
 new(a);
 a^.left:=nil;
 a^.right:=nil;
 a^.n:=n;
end;
end;

procedure maketree(var p:tree; var inf:TF);
var n:T;
begin
while not(eof(inf)) do
begin
 read(inf,n);
 addleaf(p,n);
end;
end;