int main()
{
struct student{
char name[20];
int qm;
int py;
char gb;
char xb;
int lw;
int tot;
}stu[10];
int i,n,max=-1,maxi=0,tot=0; char tmp1,tmp2;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",stu[i].name);
scanf("%d%d",&stu[i].qm,&stu[i].py);
scanf("%c%c%c%c",&tmp1,&stu[i].gb,&tmp2,&stu[i].xb);
scanf("%d",&stu[i].lw);
}
for(i=1;i<=n;i++)
{
stu[i].tot=0;
if(stu[i].qm>80&&stu[i].lw>=1) stu[i].tot+=8000;
if(stu[i].qm>85&&stu[i].py>80) stu[i].tot+=4000;
if(stu[i].qm>90) stu[i].tot+=2000;
if(stu[i].qm>85&&stu[i].xb=='Y') stu[i].tot+=1000;
if(stu[i].py>80&&stu[i].gb=='Y') stu[i].tot+=850;
if(max<stu[i].tot) {max=stu[i].tot; maxi=i;}
tot+=stu[i].tot;
}
printf("%s\n",stu[maxi].name);
printf("%d\n",max);
printf("%d",tot);
return 0;
}