#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
string a;
int b, c, f;
char d, e;
int maxmo = 0, summo = 0;
string name = "";
while (n--)
{
cin >> a >> b >> c >> d >> e >> f;
int mo = 0;
if (b > 80 && f > 0)
mo += 8000;
if (b > 85 && c > 80)
mo += 4000;
if (b > 90)
mo += 2000;
if (b > 85 && e == 'Y')
mo += 1000;
if (c > 80 && d == 'Y')
mo += 850;
if (mo > maxmo)
{
maxmo = mo;
name = a;
}
summo += mo;
}
cout << name << endl
<< maxmo << endl
<< summo;
return 0;
}