program DWITEGolfTournament; uses crt; type partrec = record name:string[50]; score:integer; end; var infile,outfile:text; n: integer; holescore: integer; participant: array[1..2000] of partrec; x,y:integer; temp: partrec; swap:boolean; begin assign(infile,'DATA11.txt'); reset(infile); assign(outfile,'OUT11.txt'); rewrite(outfile); readln(infile,n); for x:=1 to n do begin readln(infile,participant[x].name); participant[x].score:=0; for y:=1 to 9 do begin readln(infile,holescore); participant[x].score:=participant[x].score+holescore; end; end; repeat swap:=false; for x:=1 to n-1 do begin if participant[x].name>participant[x+1].name then begin temp:=participant[x]; participant[x]:=participant[x+1]; participant[x+1]:=temp; swap:=true; end; end; until not(swap); repeat swap:=false; for x:=1 to n-1 do begin if participant[x].score>participant[x+1].score then begin temp:=participant[x]; participant[x]:=participant[x+1]; participant[x+1]:=temp; swap:=true; end; end; until not(swap); for x:=1 to 5 do writeln(outfile, participant[x].name,' ',participant[x].score); writeln; close(infile); close(outfile); end.