#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,string> PIS;
const int N=110;
vector<PIS> peo;
int main()
{
int n;
cin>>n;
while(n--)
{
string s;cin>>s;
int last,qimo,lun;cin>>last>>qimo;
char b[2],x[2];scanf("%s%s",b,x);
cin>>lun;
int sum=0;
if(last>=80 && lun>=1) sum+=8000;
if(last>=85 && qimo>=80) sum+=4000;
if(last>=90) sum+=2000;
if(last>=85 && *x=='Y') sum+=1000;
if(qimo>=80 && *b=='Y') sum+=850;
peo.push_back({sum,s});
}
int res=0;
sort(peo.begin(),peo.end());
auto student=peo.end()-1;
string ress;
bool flag=0;
for(auto &stu:peo)
{
res+=stu.first;
if(stu.first>=student->first && !flag)
{
ress=stu.second;
flag=1;
}
}
cout<<student->first<<endl<<ress<<endl;
cout<<res<<endl;
return 0;
}