#include<map>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct schoolType {
string name;
int sb, sa, st;
int ns, tws;
};
bool com(schoolType a, schoolType b) {
if (a.tws > b.tws) return true;
else if (a.tws < b.tws) return false;
else if (a.ns < b.ns) return true;
else if (a.ns > b.ns) return false;
else return a.name < b.name;
}
string trueschool(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = s[i] - 'A' + 'a';
}
}
return s;
}
int main() {
int n;
cin >> n;
string id, school;
map<string, int> mp;
int score;
int i = 0;
vector<schoolType> sl; // school list
map<string, int>::iterator it;
if (n == 0) {
cout << 0 << endl;
return 0;
}
while(n--) {
cin >> id >> score >> school;
school = trueschool(school);
it = mp.find(school);
if (it == mp.end()) {
mp[school] = i;
schoolType schooltemp;
schooltemp.sb = schooltemp.sa = schooltemp.st = schooltemp.ns = 0;
schooltemp.name = school;
sl.push_back(schooltemp);
i++;
}
int t = mp[school];
sl[t].ns++;
if (id[0] == 'B') sl[t].sb += score;
else if (id[0] == 'A') sl[t].sa += score;
else sl[t].st += score;
}
for (int j = 0; j < i; j++) {
double d = sl[j].sb / 1.5 + sl[j].sa + sl[j].st * 1.5;
sl[j].tws = d;
}
sort(sl.begin(), sl.end(), com);
int r = 1; // the rank of the last school
score = -1; // the tws of the last school
cout << mp.size() << endl;
cout << r << ' ' << sl[0].name << ' ' << sl[0].tws << ' ' << sl[0].ns << endl;
for (int j = 1; j < i; j++) {
if (sl[j].tws != sl[j - 1].tws) r = j + 1;
cout << r << ' ' << sl[j].name << ' ' << sl[j].tws << ' ' << sl[j].ns << endl;
}
return 0;
}