#include <iostream>
#include<queue>
using namespace std;

int main() {
    int n;cin>>n;
    priority_queue<int,vector<int>,greater<int>>s;
    while(n--){
        int op;cin>>op;
        if(op==1){
            int x;cin>>x;
            s.push(x);
        }else if(op==2){
            cout<<s.top()<<endl;
        }else{
            s.pop();
        }
    }
}
// 64 位输出请用 printf("%lld")