what's wrong?
program ural;
uses math;
var s:array['X'..'Z']of integer;
c:char;
d,n,i:integer;
begin
readln(n);
for i:=1 to n do
begin
read(c);
readln(d);
s[c]:=s[c]+d;
end;
if(s['X']>0)and(s['Z']>0)then
begin
d:=min(s['X'],s['Z']);
inc(s['Y'],d);
dec(s['X'],d);
dec(s['Z'],d);
end
else
if(s['X']<0)and(s['Z']<0)then
begin
d:=max(s['X'],s['Z']);
inc(s['Y'],d);
dec(s['X'],d);
dec(s['Z'],d);
end;
if(s['X']>0)and(s['Y']<0)then
begin
d:=max(-s['X'],s['Y']);
inc(s['Z'],d);
inc(s['X'],d);
dec(s['Y'],d);
end
else
if(s['X']<0)and(s['Y']>0)then
begin
d:=min(-s['X'],s['Y']);
inc(s['Z'],d);
inc(s['X'],d);
dec(s['Y'],d);
end;
if(s['Z']>0)and(s['Y']<0)then
begin
d:=max(-s['Z'],s['Y']);
inc(s['X'],d);
inc(s['Z'],d);
dec(s['Y'],d);
end
else
if(s['Z']<0)and(s['Y']>0)then
begin
d:=min(-s['Z'],s['Y']);
inc(s['X'],d);
inc(s['Z'],d);
dec(s['Y'],d);
end;
writeln(abs(s['X'])+abs(s['Y'])+abs(s['Z']));
if s['X']<>0 then
writeln('X ',-s['X']);
if s['Y']<>0 then
writeln('Y ',-s['Y']);
if s['Z']<>0 then
writeln('Z ',-s['Z']);
end.