#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int N,Q; cin>>N>>Q; vector>> P(2); vector ans; rep(i,Q){ int t; cin>>t; if(t==1){ string S; int R; cin>>S>>R; P[0].emplace_back(R,S); sort(P[0].rbegin(),P[0].rend()); } if(t==2){ int x; cin>>x; N -= x; } if(t==3){ int x; string s; cin>>s>>x; N += x; rep(j,P[0].size()){ if(P[0][j].second == s){ P[1].push_back(P[0][j]); P[0].erase(P[0].begin()+j); break; } } sort(P[1].rbegin(),P[1].rend()); } vector> tt; while(P[0].size()+P[1].size()>N){ if(P[0].size()>0){ tt.push_back(P[0].back()); P[0].pop_back(); } else{ tt.push_back(P[1].back()); P[1].pop_back(); } } sort(tt.begin(),tt.end()); rep(j,tt.size())cout<