program pcount;
var
tree:array [1..10000] of record
sum,left,right,num:longint;
end;
i,now,l,last,tmp,n:longint;
new:boolean;
procedure go(root:integer);
begin
if root<>0 then begin
go(tree[root].left);
writeln (tree[root].num,' ',tree[root].sum);
go(tree[root].right);
end;
end;
begin
fillchar (tree,sizeof(tree),0);
assign (input,'pcount.in');
reset (input);
readln (n);
assign (output,'pcount.out');
rewrite (output);
readln (tree[1].num);
tree[1].sum:=1;last:=1;
for i:=2 to n do begin
readln (tmp);
now:=1;new:=true;
repeat
if tmp=tree[now].num then begin
inc(tree[now].sum);
new:=false;break;
end
else begin
l:=now;
if tmp<tree[now].num then now:=tree[now].left else now:=tree[now].right;
end;
until now=0;
if new then begin
inc(last);
if tmp<tree[l].num then tree[l].left:=last else tree[l].right:=last;
tree[last].num:=tmp;
tree[last].sum:=1;
end;
end;
close (input);
go(1);
close (output);
end.