#include "bits/stdc++.h" #define REP(i,n,N) for(ll i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const ll mod= 1e9+7; int AC[26]; int L[26]; map> score_time; map>> score; int main(){ int N,T; cin>>N; REP(i,0,N){ cin>>L[i]; } cin>>T; REP(i,0,T){ string name; char P; cin>>name>>P; AC[P-'A']++; int scores = L[P-'A']*50 + 250*L[P-'A']/(4+AC[P-'A']); score[name].push_back({P-'A',scores}); score_time[name].first += scores; score_time[name].second = -i; } vector, string>> vt; for(auto m:score_time){ vt.push_back({m.second,m.first}); } sort(ALL(vt)); reverse(ALL(vt)); REP(i,0,vt.size()){ auto scores = score[vt[i].second]; sort(ALL(scores)); cout<