#include using namespace std; int main() { int N, Q; cin >> N >> Q; //人を並べるためのpriority_queue priority_queue, vector>, greater>> que; //使用可能にしたかどうかを管理するmap map mp; for(int i = 0;i < Q; i++) { int q; cin >> q; if(q == 1) { string s; int r; cin >> s >> r; mp[s] = false; que.push({r, s}); } if(q == 2) { int x; cin >> x; N -= x; } if(q == 3) { string s; int x; cin >> s >> x; mp[s] = true; N += x; } if((q == 1 || q == 2) && (int)que.size() > N) { set> S; while((int)que.size() > N) { if(mp[que.top().second] == true && que.top().first <= 4000) { que.push({que.top().first + 5000, que.top().second}); que.pop(); } else { S.insert({que.top().first%5000,que.top().second}); que.pop(); } } for(auto j : S) { cout << j.second << endl; } } } }