#include using namespace std; #ifndef ONLINE_JUDGE #include "algo/debug.h" #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long void solve() { int n, q; cin >> n >> q; set> spec, nor, ans; map rat; while (q--) { int op; cin >> op; if (op == 1) { string s; int r; cin >> s >> r; nor.insert({r, s}); rat[s] = r; } else if (op == 2) { int x; cin >> x; n -= x; } else { string s; int x; cin >> s >> x; n += x; auto it = (nor.find({rat[s], s})); if (it != nor.end()) { nor.erase(it); } spec.insert({rat[s], s}); } n = min(n, (int)1e9); while (nor.size() + spec.size() > n) { if (nor.size()) { ans.insert(*nor.begin()); nor.erase(nor.begin()); } else if (spec.size()) { ans.insert(*nor.begin()); spec.erase(spec.begin()); } } } for (auto &x : ans) { cout << x.second << '\n'; } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } // cerr << "Time elapsed: " << ((long double)clock() / CLOCKS_PER_SEC) << " s.\n"; }