#include<bits/stdc++.h>
using namespace std;
multiset<int> st;
void insertValue(int x){
    //TODO 实现插入逻辑
    st.insert(x);
    return;
}
void eraseValue(int x){
    //TODO 实现删除逻辑
	auto it=st.find(x);
	if(it!=st.end()){
		st.erase(it);
	}
    return;
}
int xCount(int x){
    //TODO 求x在集合中的个数
    return st.count(x);
}
int sizeOfSet(){
    //TODO 返回集合大小
    return st.size();
}
int getPre(int x){
    //TODO 实现找前驱
    auto it=st.lower_bound(x);
    if(it==st.begin()){
    	return -1;
	}else{
		return *(--it);
	}
}
int getBack(int x){
    //TODO 实现找后继
    auto it=st.upper_bound(x);
    if(it==st.end()){
    	return -1;
	}else{
		return *it;
	}
}

int main(){
    int q,op,x;
    cin>>q;
    while(q--){
        cin>>op;
        if(op==1){
            cin>>x;
            insertValue(x);
        }
        if(op==2){
            cin>>x;
            eraseValue(x);
        }
        if(op==3){
            cin>>x;
            cout<<xCount(x)<<endl;
        }
        if(op==4){
            cout<<sizeOfSet()<<endl;
        }
        if(op==5){
            cin>>x;
            cout<<getPre(x)<<endl;
        }
        if(op==6){
            cin>>x;
            cout<<getBack(x)<<endl;
        }
    }
    return 0;
}