#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int qmcj,pycj;
char gb,xb;
int lw,jxj=0;
}a[100001];
bool ys(node x){
if(x.qmcj>80&&x.lw>0) return 1;
return 0;
}
bool ws(node x){
if(x.qmcj>85&&x.pycj>80) return 1;
return 0;
}
bool cj(node x){
if(x.qmcj>90) return 1;
return 0;
}
bool xb(node x){
if(x.qmcj>85&&x.xb=='Y') return 1;
return 0;
}
bool gx(node x){
if(x.pycj>80&&x.gb=='Y') return 1;
return 0;
}
int main(){
int n,sum=0;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].name>>a[i].qmcj>>a[i].pycj>>a[i].gb>>a[i].xb>>a[i].lw;
for(int i=1;i<=n;i++){
if(ys(a[i])) a[i].jxj+=8000;
if(ws(a[i])) a[i].jxj+=4000;
if(cj(a[i])) a[i].jxj+=2000;
if(xb(a[i])) a[i].jxj+=1000;
if(gx(a[i])) a[i].jxj+=850;
}
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
if(a[j].jxj>a[i].jxj)
swap(a[i],a[j]);
for(int i=1;i<=n;i++) sum+=a[i].jxj;
cout<<a[n].name<<endl<<a[n].jxj<<endl;
cout<<sum;
return 0;
}