#include<iostream> #include<queue> #include<string> struct news{ int lev; int num; bool operator <(const news a)const{ return this->lev==a.lev?this->num>a.num:this->lev<a.lev; } }; using namespace std; int main() { int n; while(cin>>n) { int cut=0; priority_queue<news> q[4]; for(int i=0;i<n;++i) { string str; cin>>str; if(str == "IN") { cut++; news so; int k; cin>>k>>so.lev; so.num=cut; q[k].push(so); } else if(str == "OUT") { int i; cin>>i; if(!q[i].empty()) { cout<<q[i].top().num<<endl; q[i].pop(); } else cout<<"EMPTY "; } } } return 0; }