{$apptype console} {$R+,O-} { This program delete equal pairs from first_fres.txt file. The program writes result to fres.txt file. This file contains pairs $(n(w),|w|)$. } var f:text; {array that contains pair from fres.txt file} data:array[1..200000,1..2] of integer; {number of pairs} ndata:integer; {Read pairs from first_fres.txt file and store them in data array.} procedure loaddata; var s:string; i:integer; code:integer; s1:string; begin ndata:=0; while not eof(f) do begin {data is written in $w$/$n(w)$ format} readln(f,s); i:=pos('/',s); if i=0 then halt; s1:=copy(s,1,i-1);{s1 contains $w$ now} delete(s,1,i);{s contains $n(w)$ now} inc(ndata); {convert strings to numbers} val(s1,data[ndata,1],code); if code<>0 then halt; val(s,data[ndata,2],code); if code<>0 then halt; end; end; {lexicographical comparing of pairs} function cmp(a,b:integer):boolean; begin if data[a,1]<>data[b,1] then cmp:=data[a,1]1 do begin trans(1,ndata); dec(ndata); heap(1); end; ndata:=prevn; end; {Calculate unique pairs} procedure solve; var i,j:integer; begin sort; j:=1; for i:=2 to ndata do begin if (data[i,1]<>data[i-1,1]) or (data[i,2]<>data[i-1,2]) then begin inc(j); data[j,1]:=data[i,1]; data[j,2]:=data[i,2]; end; end; ndata:=j; end; {Save unique pairs to the file} procedure writedata; var i:integer; begin writeln(f,ndata); for i:=1 to ndata do begin writeln(f,data[i,1],' ',data[i,2]); end; end; begin assign(f,'first_res.txt'); reset(f); loaddata; close(f); solve; assign(f,'fres.txt'); rewrite(f); writedata; close(f); end.