#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<29; const ll MOD = 1000000007; const double EPS = 1e-10; int n, l[26]; int t; int score[4000][26], lastt[4000]; int rnk[26]; map namenum; string revname[4000]; int main() { cin >> n; REP(i, n) scanf("%d", l + i); cin >> t; REP(i, t) { string name, pro; cin >> name >> pro; if (namenum.find(name) == namenum.end()) { namenum[name] = namenum.size() - 1; revname[namenum[name]] = name; } int pnum = pro[0] - 'A'; int nnum = namenum[name]; rnk[pnum]++; score[nnum][pnum] = 50 * l[pnum] + (500 * l[pnum]) / (8 + 2 * rnk[pnum]); lastt[nnum] = i; } vector

v; REP(i, namenum.size()) { int sum = 0; REP(j, n) sum += score[i][j]; v.push_back(P(sum, pii(-lastt[i], i))); } sort(ALL(v), greater

()); REP(i, v.size()) { int p = v[i].second.second; printf("%d %s ", i + 1, revname[p].c_str()); REP(j, n) printf("%d ", score[p][j]); printf("%d\n", v[i].first); } return 0; }