#include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int main() { int n; cin >> n; int q; cin >> q; unordered_map rate; set S, T; vector ans; while(q--) { int t; cin >> t; if(t==1){ string s; int r; cin >> s >> r; rate[s] = r; S.emplace(s); } else if(t==2){ int x; cin >> x; n-=x; } else{ string s; int x; cin >> s >> x; n+=x; S.erase(s); T.insert(s); } vector> vs; for(auto t : T) { vs.emplace_back(rate[t], t); } dbg(S,T); int N = n; sort(vs.rbegin(),vs.rend()); vector> tmp; for(auto [r, t] : vs) { if(N==0) { tmp.emplace_back(rate[t], t); continue; } N--; } vs.clear(); for(auto t : S) { vs.emplace_back(rate[t], t); } sort(vs.rbegin(),vs.rend()); for(auto [r, t] : vs) { if(N==0) { tmp.emplace_back(rate[t], t); continue; } N--; } sort(tmp.begin(),tmp.end()); for(auto t : tmp) { ans.push_back(t.second); if(S.count(t.second)) S.erase(t.second); if(T.count(t.second)) T.erase(t.second); } } for(auto a : ans) { cout << a << " "; } cout << endl; return 0; }