#include <iostream>
#include <queue>
//优先队列的头文件也是queue
using namespace std;
//本题为模板题,没有特别的说明,学习语法即可
int main() {
    priority_queue<int> a;//定义一个优先队列(默认大根堆)
    int q{};//q次操作
    cin>>q;
    while(q--)
    {
        int op{};//定义操作类型
        cin>>op;
        if(op==1)//第一种操作类型
        {
            int x{};
            cin>>x;
            a.push(-x);//读入数据的负值,实现小根堆的功能
        }
        else if(op==2)
        {
            cout<<-a.top()<<endl;//用负号转化为原始数据
        }
        else
        {
            a.pop();//出队
        }
    }


    return 0;
}
// 64 位输出请用 printf("%lld")