#include using namespace std; int main(){ int N; cin>>N; vector L(N); for(int i=0;i>L[i]; } int T; cin>>T; int temp; string name; int people=0; char P; map m,last; map revm; vector answered(N); vector> ans(0,vector(N+2)); for(int i=0;i>name>>P; if(!m.count(name)){ m[name]=people; revm[people]=name; people++; ans.push_back(vector(N+2)); ans[people-1][0]=people-1; } last[name]=i; answered[P-'A']++; temp=50*L[P-'A']+250*L[P-'A']/(4+answered[P-'A']); ans[m[name]][P-'A'+1]=temp; ans[m[name]][N+1]+=temp; } auto fn=[&](vector& a,vector& b){ if(a[N+1]==b[N+1]){ return last[revm[a[0]]]b[N+1]; }; sort(ans.begin(),ans.end(),fn); for(int i=1;i<=people;i++){ cout<