nam,xam:string;
na:char;
n,i,j,qc,bc,ly,jj,max:integer;
xg,xb:boolean;
sum:longint;
begin
readln(n);
for i:=1 to n do
begin
jj:=0;
nam:='';
for j:=1 to 20 do
begin
read(na);
if na=' ' then
break
else
nam:=nam+na;
end;
read(qc,bc,na);
na:='1';
read(na);
if na='Y' then
xg:=true
else
xg:=false;
read(na);
na:='1';
read(na,ly);
if na='Y' then
xb:=true
else
xb:=false;
if (qc>80) and (ly>0) then
jj:=jj+8000;
if (qc>85) and (bc>80) then
jj:=jj+4000;
if qc>90 then
jj:=jj+2000;
if (qc>80) and xb then
jj:=jj+1000;
if (qc>80) and xg then
jj:=jj+850;
if jj>max then
begin
max:=jj;
xam:=nam;
end;
sum:=sum+jj;
end;
writeln(xam);
writeln(max);
writeln(sum);
end.