#include<bits/stdc++.h>
using namespace std;
string m,j;
int main(){
int n,v=0,a,b,t=0,e;
char c,d;
cin>>n;
for(int i=0;i<n;i++){
cin>>m>>a>>b>>c>>d>>e;
int h=0;
if(a>80&&e>0)v+=8000;
if(a>85&&b>80)v+=4000;
if(a>90)v+=2000;
if(a>85&&d=='Y')v+=1000;
if(b>80&&c=='Y')v+=850;
if(a>80&&e>0)h+=8000;
if(a>85&&b>80)h+=4000;
if(a>90)h+=2000;
if(a>85&&d=='Y')h+=1000;
if(b>80&&c=='Y')h+=850;
if(t<h){
t=h;
j=m;
}
}
cout<<j<<"\n"<<t<<"\n"<<v;
return 0;
}