#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
// 交换
void swap(vector<int> &arr,int a,int b){
int temp=arr[a];
arr[a]=arr[b];
arr[b]=temp;
}
void getMax(vector<int> &arr){
int max=0;
for(int i=1;i<arr.size();i++){
if(arr[i]>arr[max])max=i;
}
swap(arr,max,0);
}
int main() {
vector<int> arr;
// 输入操作次数
int n;
cin>>n;
//getline 会多出一个空行 判断条件取等号
for(int i=0;i<=n;i++){
// 按行取操作
string str;
getline(cin,str);
// push操作 入堆 构造大顶堆
if(str.length()>3){
int yt=atoi(str.substr(4).c_str());
arr.push_back(yt);
getMax(arr);
}//top 操作 探空 输出
else if(str.compare("top")==0){
if(!arr.empty()){
cout<<arr[0]<<endl;
}else cout<<"empty"<<endl;
}// pop操作 探空输出 并且出堆
else if(str.compare("pop")==0){
if(!arr.empty()){
cout<<arr[0]<<endl;
arr.erase(arr.begin());
getMax(arr);
}else cout<<"empty"<<endl;
}else continue;
}
return 0;
}
// 64 位输出请用 printf("%lld")