#include<bits/stdc++.h>
inline void read(int &a)
{
a=0;char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
}
inline void write(int a)
{
if(a<0){putchar('-');a=-a;}
if(a>9)write(a/10);
putchar(a%10+'0');
}
int line[100001],num=0;
inline int find(int x)
{
int l=1,r=num;
while(l!=r)
{
int mid=l+r>>1;
if(line[mid]==x)return mid;
if(line[mid]>x)r=mid-1;
else l=mid+1;
}
return l;
}
int main()
{
memset(line,0,sizeof(line));
int m;int order,x;
read(m);
while(m--)
{
read(order);read(x);
if(order==1)
{
line[++num]=x;
int d=num;
while(d-1&&line[d]<line[d-1]){std::swap(line[d],line[d-1]);--d;}
}
if(order==2)
{
int k=find(x);
line[k]=0;
for(int i=k;i<=num-1;i++)line[i]=line[i+1];
line[num]=0;
--num;
}
if(order==3)
{
write(line[x]);puts("");
}
}
return 0;
}