#include #include #include #include #include #include using namespace std; int now; int Q; mapR; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>now>>Q; set >cur; for(;Q--;) { int op;cin>>op; if(op==1) { string s;int r;cin>>s>>r; R[s]=r; cur.insert(make_pair(R[s],s)); } else if(op==2) { int x;cin>>x; now-=x; } else { string s;int x;cin>>s>>x; now+=x; assert(cur.find(make_pair(R[s],s))!=cur.end()); if(R[s]<=4000) { cur.erase(make_pair(R[s],s)); R[s]+=10000; cur.insert(make_pair(R[s],s)); } } vector >out; while(now