#include<bits/stdc++.h>
using namespace std;
int Q,op,x;set<int>S;
int main(){
cin>>Q;
for (int i=0; i<Q;++i) {
cin>>op>>x;
if (op==1) {
int temp=S.count(x);
if (temp==0) {
S.insert(x);
}else {
cout<<"Already Exist"<<endl;
}
}else if (op==2) {
if (S.empty()) {
cout<<"Empty"<<endl;
}else {
int temp=S.count(x);
if (temp==1) {
cout<<x<<endl;
S.erase(x);
}else if (temp==0) {
auto houji=S.lower_bound(x);
if (houji==S.end()) {
houji--;
cout<<*(houji)<<endl;
S.erase(houji);
}else if (houji==S.begin()) {
cout<<*houji<<endl;
S.erase(houji);
}else {
auto qianqu=houji;
qianqu--;
if ((*(houji)-x)>(x-*(qianqu))) {
cout<<*qianqu<<endl;
S.erase(qianqu);
}else if ((*(houji)-x)<(x-*(qianqu))) {
cout<<*houji<<endl;
S.erase(houji);
}else {
cout<<*qianqu<<endl;
S.erase(qianqu);
}
}
}else {
cout<<"error_1"<<endl;
}
}
}else {
cout<<"error_2"<<endl;
}
}
return 0;
}

京公网安备 11010502036488号