#include<bits/stdc++.h>
#include<bits/extc++.h>
#define ll long long
#define inf 2147482647
using namespace std;
using namespace __gnu_pbds;
tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> te;
int q,x,y;
int main(){
cin>>q;
while(q--){
cin>>x>>y;
if(x==1) cout<<te.order_of_key(y)+1<<'\n';
else if(x==2) cout<<(*te.find_by_order(y-1))<<'\n';
else if(x==5) te.insert(y);
else{
if(x==3){
if(--te.lower_bound(y)==te.end())
cout<<-inf<<'\n';
else cout<<(*--te.lower_bound(y))<<'\n';
}else if(x==4){
if(te.lower_bound(y+1)==te.end())
cout<<inf<<'\n';
else cout<<(*te.lower_bound(y+1))<<'\n';
}
}
}return 0;
}