qm,bj,lw,tm:array[1..100]of integer;
xg,xb:array[1..100]of char;
i,j,n,ts,tz,x:integer;
ch:string;
begin
readln(n);
for i:=1 to n do
begin
readln(ch);
ch:=ch+' ';
j:=pos(' ',ch);
nm[i]:=copy(ch,1,j-1);
delete(ch,1,j);
j:=pos(' ',ch);
val(copy(ch,1,j-1),qm[i]);
delete(ch,1,j);
j:=pos(' ',ch);
val(copy(ch,1,j-1),bj[i]);
delete(ch,1,j);
xg[i]:=ch[1];
xb[i]:=ch[3];
delete(ch,1,4);
j:=pos(' ',ch);
val(copy(ch,1,j-1),lw[i]);
end;
for i:=1 to n do
tm[i]:=0;
for i:=1 to n do
begin
if (qm[i]>80)and(lw[i]>0) then tm[i]:=tm[i]+8000;
if (qm[i]>85)and(bj[i]>80) then tm[i]:=tm[i]+4000;
if (qm[i]>90) then tm[i]:=tm[i]+2000;
if (qm[i]>85)and(xb[i]='Y') then tm[i]:=tm[i]+1000;
if (bj[i]>80)and(xg[i]='Y') then tm[i]:=tm[i]+850;
end;
ts:=0;
x:=0;
tz:=0;
for i:=1 to n do
if tm[i]>ts then
begin
ts:=tm[i];
x:=i;
end;
for i:=1 to n do
tz:=tz+tm[i];
writeln(nm[x]);
writeln(tm[x]);
writeln(tz);
end.