#include<bits/stdc++.h>
using namespace std;
#include <set>
set<int>op_set;
void insertValue(int x){
//TODO 实现插入逻辑
op_set.insert(x);
}
void eraseValue(int x){
//TODO 实现删除逻辑
op_set.erase(x);
}
int xInSet(int x){
//TODO 实现存在性检查
return op_set.count(x);
}
int sizeOfSet(){
//TODO 返回集合大小
return op_set.size();
}
int getPre(int x){
//TODO 实现找前驱
auto it=op_set.lower_bound(x);
if(it==op_set.begin())return -1;
it--;
return *it;
}
int getBack(int x){
//TODO 实现找后继
if(op_set.upper_bound(x)==op_set.end())return -1;
return *op_set.upper_bound(x);
}
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;
}