#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct BIT{ Int n; vector bit; //1-indexed BIT():n(-1){} BIT(Int n_,T d):n(n_),bit(n_+1,d){} T sum(Int i){ T s=bit[0]; for(Int x=i;x>0;x-=(x&-x)) s+=bit[x]; return s; } void add(Int i,T a){ if(i==0) return; for(Int x=i;x<=n;x+=(x&-x)) bit[x]+=a; } Int lower_bound(Int w){ if(w<=0) return 0; Int x=0,r=1; while(r0;k>>=1){ if(x+k<=n&&bit[x+k] vector compress(vector v){ sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return v; } template map dict(const vector &v){ map res; for(Int i=0;i<(Int)v.size();i++) res[v[i]]=i; return res; } //INSERT ABOVE HERE signed main(){ int n; cin>>n; vector l(n); for(int i=0;i>l[i]; vector cnt(n,0); auto sc=[&](int x){return 50*l[x]+(500*l[x]/(8+2*++cnt[x]));}; int q; cin>>q; vector ss; vector ps; map lst,sum; using P = pair; vector

vp; for(int i=0;i>s>>p; if(isalpha(p)){ lst[s]=i; sum[s]+=sc(p-'A'); } vp.emplace_back(-sum[s],i); ss.emplace_back(s); ps.emplace_back(p); } vp.emplace_back(0,0); vp.emplace_back(1e9,-1); vp=compress(vp); auto dc=dict(vp); int m=lst.size(); BIT bit(vp.size(),0); bit.add0(dc[P(0,0)],m); cnt.assign(n,0); lst.clear(); sum.clear(); for(int i=0;i