///之前因为没有及时continue导致了迭代器失效 和 逻辑穿透
#include <iostream>
#include <set>
using namespace std;
set<int> s;
int main() {
int x, q, op;
cin >> q;
while (q--) {
cin >> op >> x;
if (op == 1) {
if (s.count(x))
{
cout << "Already Exist" << endl;
}
else {
s.insert(x);
}
}
else if (op == 2)
{
if (s.empty()) {
cout << "Empty" << endl;
continue;
}
if(x <= *s.begin())
{
cout << *s.begin() << endl;
s.erase(*s.begin());
continue;
}
else if(x >= *(--s.end()))
{
cout << *(--s.end()) << endl;
s.erase(*(--s.end()));
continue;
}
int a,b;
auto it = s.lower_bound(x);
a = *it;
b = *--it;
if(abs(a-x)>=abs(x-b))
{
cout << b << endl;
s.erase(b);
}
else {
cout << a << endl;
s.erase(a);
}
}
}
return 0;
}