/*优先队列的小根堆的写法。水题。
还有一个方法是将所有的值都变为负数,然后直接用优先队列。
输出输入和输出还有字符串用c,不然tle。*/
#include <iostream>
#include <queue>
#include <cstring>
#include <stdio.h>
using namespace std;
int main()
{
priority_queue<int,vector<int>,greater<int> > v;
char s[20];
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%s",s);
if(strcmp(s,"add")==0)
{
scanf("%d",&n);
v.push(n);
}
else if(s[0]=='d')
{
if(v.empty()) continue;
else v.pop();
}
else
{
if(!v.empty())
printf("%d\n",v.top());
else continue;
}
}
return 0;
}