#include <cmath>
using namespace std;
template <typename T, typename U>
struct node {
T key;
U val;
node *l, *r;
int h;
node(const T &key, const U &val, int l, node* v): key(key), val(val), l(v), r(v), h(l) {}
};
#define NULL dead
template <typename T, typename U>
class AVL {
node <T, U> *head;
node <T, U> *dead;
node<T, U> *priv_insert(node<T,U> *root, const T &key, const U &val) {
if(root == NULL) {
node<T,U> *p = new node<T,U>(key, val, 0, dead);
return p;
}
if(root -> key == key) {
root -> val = val;
return root;
}
if(root -> key < key)
root->r = priv_insert(root->r, key, val);
else
root->l = priv_insert(root->l, key, val);
return balance(root);
}
node<T,U> *priv_isIn(node<T,U> *root, const T &key) {
while(root != NULL && root->key != key) {
if(root->key < key)
root = root->r;
else
root = root->l;
}
return root;
}
node<T,U> *priv_del(node<T,U> *root, const T &key) {
if(root == NULL)
return NULL;
if(root -> key == key) {
node<T,U> *p;
if(root -> l == NULL || root -> r == NULL) {
root->l == NULL ? p = root->r : p = root->l;
delete root;
return p;
}
p = root->l;
while(p->r != NULL)
p = p->r;
root->key = p->key;
root->val = p->val;
root->l = priv_del(p, p->key);
return balance(root);
}
if(root->key > key)
root->l = priv_del(root->l, key);
else
root->r = priv_del(root->r, key);
return balance(root);
}
void comp_height(node<T,U> *root) {
if(root == NULL)
return;
else
root->h = 1 + max(root->l->h, root->r->h);
}
node<T,U> *balance(node<T,U> *root) {
comp_height(root);
if(abs(root->l->h - root->r->h) <= 1)
return root;
if(root->l->h > root->r->h) {
if(root->l->l->h < root->l->r->h)
root->l = left_rot(root->l);
root = right_rot(root);
}
else {
if(root->r->l->h > root->r->r->h)
root->r = right_rot(root->r);
root = left_rot(root);
}
return root;
}
node<T,U>* left_rot(node<T,U> *root) {
node<T, U> *p = root->r;
root->r = root->r->l;
p->l = root;
return p;
}
node<T,U>* right_rot(node<T,U> *root) {
node<T, U> *p = root->l;
root->l = root->l->r;
p->r = root;
return p;
}
public:
AVL () {
dead = new node<T,U>(T(), U(), -1, NULL);
head = NULL;
}
void insert(const T &key, const U &val) {
head = priv_insert(head, key, val);
}
bool isIn(const T &key) {
node<T,U> *p = priv_isIn(head, key);
if(p != NULL)
return true;
else return false;
}
void del(const T &key) {
head = priv_del(head, key);
}
};
#include <fstream>
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int main()
{
int T;
f>>T;
AVL<int, bool> tree;
int q,x;
while(T--)
{
f>>q>>x;
switch (q)
{
case 1: tree.insert(x, true); break;
case 2: tree.del(x); break;
case 3: g<<tree.isIn(x)<<'\n'; break;
}
}
}