#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; int main() { int N, Q; cin >> N >> Q; map rate; set> come, done; int nowp = N, nowh = 0; vector ans; while (Q--) { int t; cin >> t; if (t == 1) { string s; int r; cin >> s >> r; rate[s] = r; come.insert({r, s}); nowh++; } else if (t == 2) { int x; cin >> x; nowp -= x; } else { string s; int r; cin >> s >> r; come.erase({rate[s], s}); done.insert({rate[s], s}); nowp += r; } if (nowp < nowh) { vector cont_d, cont_c; while (cont_d.size() < nowp && done.size() > 0) { auto [r, s] = *done.rbegin(); done.erase({r, s}); cont_d.push_back(s); } while (cont_d.size() + cont_c.size() < nowp && come.size() > 0) { auto [r, s] = *come.rbegin(); come.erase({r, s}); cont_c.push_back(s); } nowh = nowp; vector> other; for (auto [r, s] : done) { other.push_back({r, s}); } for (auto [r, s] : come) { other.push_back({r, s}); } sort(other.begin(), other.end()); for (auto [r, s] : other) { ans.push_back(s); } done.clear(); come.clear(); for (string x : cont_d) { done.insert({rate[x], x}); } for (string x : cont_c) { come.insert({rate[x], x}); } } } for (string x : ans) { cout << x << endl; } }