#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=15<<26; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N;cin>>N; int Q;cin>>Q; set<pair<int,string>> A,B; map<string,int> MA; int cn=N; while(Q--){ int t;cin>>t; if(t==1){ string X;cin>>X; int z;cin>>z; A.insert(mp(z,X)); MA[X]=z; } if(t==2){ int x;cin>>x; cn-=x; } if(t==3){ string X;cin>>X; int z;cin>>z; if(A.count(mp(MA[X],X))){ B.insert(mp(MA[X],X)); A.erase(mp(MA[X],X)); } cn+=z; } vector<pair<int,string>> Z; while(si(A)+si(B)>cn){ if(si(A)){ Z.push_back(*A.begin()); //cout<<(*A.begin()).se<<"\n"; A.erase(A.begin()); }else{ Z.push_back(*B.begin()); //cout<<(*B.begin()).se<<"\n"; B.erase(B.begin()); } } sort(all(Z)); for(auto [a,b]:Z) cout<<b<<"\n"; } }