#include<bits/stdc++.h>
using namespace std;
const int MAXN=100010;
struct schnode{
string name;
int tws;
int ns;
}node[MAXN];
bool cmp(schnode a,schnode b){
if(a.tws!=b.tws) return a.tws>b.tws;
else if(a.ns!=b.ns) return a.ns<b.ns;
else return a.name<b.name;
}
int main(){
//freopen("in.txt","r",stdin);
int n;cin>>n;
map<string,double> hashtws;
map<string,int> hashns;
for(int i=0;i<n;i++){
string stuname;
int score;
string schname;
cin>>stuname>>score>>schname;
transform(schname.begin(),schname.end(),schname.begin(),::tolower);
hashns[schname]++;
if(stuname[0]=='T'){
hashtws[schname]+=score*1.5;
}else if(stuname[0]=='A'){
hashtws[schname]+=score;
}else{
hashtws[schname]+=score/1.5;
}
}
int t=0;
for(auto it=hashtws.begin();it!=hashtws.end();it++){
node[t].name=it->first;
node[t++].tws=it->second;
}
int tt=0;
for(auto it=hashns.begin();it!=hashns.end();it++){
node[tt].name=it->first;
node[tt++].ns=it->second;
}
cout<<max(tt,t)<<endl;
sort(node,node+tt,cmp);int rank=1;cout<<rank<<' ';
cout<<node[0].name<<' '<<(int)node[0].tws<<' '<<node[0].ns<<endl;
for(int i=1;i<tt;i++){
if(node[i].tws==node[i-1].tws){
cout<<rank<<' ';
}else{
rank=i+1;
cout<<rank<<' ';
}
cout<<node[i].name<<' '<<(int)node[i].tws<<' '<<node[i].ns<<endl;
}
return 0;
}