program ex;
type
sz=record
lch,rch,data,num:longint;
end;
ss=array[1..200000]of sz;
var
f:ss;
n,tot:longint;
procedure init;
var
i,x,step:longint;
begin
assign(input,'pcount.in');
assign(output,'pcount.out');
reset(input);
rewrite(output);
readln(n);
tot:=1;
x:=0;
readln(f[1].data);
inc(f[1].num);
for i:=1 to n-1 do
begin
readln(x);
step:=1;
while f[step].data<>0 do
begin
if f[step].data=x then
begin
inc(f[step].num);
break;
end;
if x>f[step].data then
if f[step].rch=0 then
begin
inc(tot);
f[tot].data:=x;
f[step].rch:=tot;
inc(f[tot].num);
break;
end
else step:=f[step].rch;
if x<f[step].data then
if f[step].lch=0 then
begin
inc(tot);
f[tot].data:=x;
f[step].lch:=tot;
inc(f[tot].num);
break;
end
else step:=f[step].lch;
end;
end;
close(input);
end;
procedure print(x:longint);
begin
if f[x].lch<>0 then print(f[x].lch);
writeln(f[x].data,' ',f[x].num);
if f[x].rch<>0 then print(f[x].rch);
end;
begin
init;
print(1);
close(output);
end.