#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b>N; int Q;cin>>Q; set> A,B; map MA; int cn=N; while(Q--){ int t;cin>>t; if(t==1){ string X;cin>>X; int z;cin>>z; A.insert(mp(z,X)); MA[X]=z; } if(t==2){ int x;cin>>x; cn-=x; } if(t==3){ string X;cin>>X; int z;cin>>z; if(A.count(mp(MA[X],X))){ B.insert(mp(MA[X],X)); A.erase(mp(MA[X],X)); } cn+=z; } while(si(A)+si(B)>cn){ if(si(A)){ cout<<(*A.begin()).se<<"\n"; A.erase(A.begin()); }else{ cout<<(*B.begin()).se<<"\n"; B.erase(B.begin()); } } } }