using namespace std;
int main()
{
int n,pj,nj,lw,money,qb,zd=0;
char xb,gb;
string rm,ds;
cin>>n;
for(int i=1;i<=n;i++)
{
money=0;
cin>>rm>>pj>>nj>>xb>>gb>>lw;
if(pj>80&&lw>=1)
{
money+=8000;
qb+=8000;
}
if(pj>85&&nj>80)
{
money+=4000;
qb+=4000;
}
if(pj>90)
{
money+=2000;
qb+=2000;
}
if(xb=='y'&&pj>85)
{
money+=1000;
qb+=1000;
}
if(gb=='y'&&nj>80)
{
money+=850;
qb+=850;
}
if(zd<money)
{
zd=money;
ds=rm;
}
}
cout<<ds<<endl<<zd<<endl<<qb<<endl;
return 0;
}