#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define POWT(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) using namespace std; typedef pair pii; typedef long long ll; const pii Dir[8] = { //????????? { 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 }, { 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 } }; template void Fill(A(&array)[N], const T &val) { std::fill((T*) array, (T*) (array + N), val); } int point(int a, int b) { return 50 * a + (int) ((500 * a) / (8 + 2 * b)); } signed main() { int n; scanf("%d", &n); vector star(n); vector monc(n); REP(i, n) { scanf("%d", &star[i]); } int t; scanf("%d", &t); map>> man; REP(i, t) { char name[17],mon; int mnum; scanf("%s%*c%c", name, &mon); mnum = mon - 'A'; monc[mnum]++; man[name].second[mnum] = point(star[mnum], monc[mnum]); man[name].first += point(star[mnum], monc[mnum]); } priority_queue> ans; for (auto itr : man) { string s; char str [1000]; sprintf(str," %s", itr.first.c_str()); s += str; REP(i, n) { sprintf(str," %d", itr.second.second[i]); s += str; } sprintf(str," %d\n", itr.second.first); s += str; ans.push({itr.second.first,s}); } int cou = 1; while (ans.size()) { printf("%d %s",cou,ans.top().second.c_str()); ans.pop(); cou++; } return 0; }