#include<bits/stdc++.h>
using namespace std;

set<int> s;
void insertValue(int x){
    s.insert(x);
    //TODO 实现插入逻辑
}
void eraseValue(int x){
    if (s.find(x) != s.end()) s.erase(x);
    //TODO 实现删除逻辑
}
int xInSet(int x){
    if (s.find(x) != s.end()) return 1;
    else return 0;;
    //TODO 实现存在性检查
}
int sizeOfSet(){
    return s.size();
    //TODO 返回集合大小
}
int getPre(int x){
    auto y = s.lower_bound(x);
    if (y != s.begin())
    {
        y--;
        return *y;
    }
    else return -1;
    //TODO 实现找前驱
}
int getBack(int x){
    if (s.upper_bound(x) != s.end()) return *s.upper_bound(x);
    else return -1;
    //TODO 实现找后继
}

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;
            if(xInSet(x)){
                cout<<"YES\n";
            }else{
                cout<<"NO\n";
            }
        }
        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;
}