#include<bits/stdc++.h>
#include <iterator>
#include <set>
using namespace std;
class sol{
private:
set<int> st;
public:
sol() {
}
void insertValue(int x){
//TODO 实现插入逻辑
st.insert(x);
}
void eraseValue(int x){
//TODO 实现删除逻辑
if(st.find(x) != st.end()){
st.erase(x);
}
}
int xInSet(int x){
//TODO 实现存在性检查
return st.find(x) != st.end();
}
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 *prev(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;
sol sl = sol();
while(q--){
cin>>op;
if(op==1){
cin>>x;
sl.insertValue(x);
}
if(op==2){
cin>>x;
sl.eraseValue(x);
}
if(op==3){
cin>>x;
if(sl.xInSet(x)){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
if(op==4){
cout<<sl.sizeOfSet()<<endl;
}
if(op==5){
cin>>x;
cout<<sl.getPre(x)<<endl;
}
if(op==6){
cin>>x;
cout<<sl.getBack(x)<<endl;
}
}
return 0;
}