#include <stdio.h>
#include <fstream>
class numar{
private:
public:
int val;
int operator()();
bool operator==(const numar& x);
};
int numar::operator()(){
return val;
}
bool numar::operator==(const numar& x){
if(this->val==x.val) return true;
return false;
}
template <class A, class B> class hashTable{
private:
int size;
int used_size;
struct nod{
A key;
B value;
nod *next;
};
nod **table;
public:
hashTable(int sz);
~hashTable();
void setSize(int size);
const int getSize();
void resize();
void add(A key, B value, bool ok);
void remove(A key);
bool get(A key);
bool operator[](A key){
return get(key);
}
};
template <class A, class B> hashTable<A,B>::hashTable(int sz){
size=sz;
used_size=0;
table=new nod*[size]();
}
template <class A, class B> hashTable<A,B>::~hashTable(){
int i;
nod *c,*aux;
for(i=0;i<size;i++){
if(table[i]!=NULL){
c=table[i];
while(c!=NULL){
aux=c->next;
delete c;
c=aux;
}
}
}
delete[] table;
}
template <class A, class B> void hashTable<A,B>::setSize(int size2){
size=size2;
}
template <class A, class B> const int hashTable<A,B>::getSize(){
return size;
}
template <class A, class B> void hashTable<A,B>::add(A key, B value, bool ok){
nod *c;
int hash;
hash=key()%size;
c=table[hash];
if(used_size<size/2){
if(c==0){
c=new nod;
c->value=value;
c->key=key;
c->next=0;
table[hash]=c;
}
else{
c=new nod;
c->value=value;
c->key=key;
c->next=table[hash];
table[hash]=c;
}
used_size++;
// if(ok==0) std::cout<<"Added element."<<std::endl;
}
else{
resize();
//std::cout<<"Table resized!"<<std::endl;
//std::cout<<"New size: "<<size<<std::endl;
add(key, value, 0);
// if(ok==0) std::cout<<"Added element."<<std::endl;
}
}
template <class A, class B> void hashTable<A,B>::remove(A key){
nod *c, *u = NULL, *aux;
int hash;
hash=key()%size;
c=table[hash];
if(c==0){
return;
// std::cout<<"Nimic de sters.";
}
else{
if(c->key==key){
aux=c;
table[hash]=c->next;
delete aux;
// std::cout<<"S-a sters.";
return;
}
while(c->next!=0){
if(c->next->key==key){
aux=c->next;
c->next=c->next->next;
delete aux;
// std::cout<<"Sters!";
return;
}
if(c->next->next==0) u=c;
c=c->next;
}
if(c->key==key){
delete c;
u->next=0;
// std::cout<<"Sters!";
return;
}
// std::cout<<"Nimic de sters.";
}
}
template <class A, class B> bool hashTable<A,B>::get(A key){
int hash;
nod *value;
hash=key()%size;
value=table[hash];
while(value!=0){
if(value->key==key){
//std::cout<<"S-a gasit: ";
return true;
}
value=value->next;
}
//std::cout<<"NU s-a gasit!\n";
return false;
}
template <class A, class B> void hashTable<A,B>::resize(){
nod *c,*aux;
int i;
hashTable<A,B> newhash(2*size);
for(i=0;i<size;i++){
c=table[i];
while(c!=NULL){
newhash.add(c->key, c->value,1);
c=c->next;
}
}
for(i=0;i<size;i++){
if(table[i]!=NULL){
c=table[i];
while(c!=NULL){
aux=c->next;
delete c;
c=aux;
}
}
}
delete[] table;
size=newhash.size;
used_size=0;
table=new nod*[size]();
for(i=0;i<size;i++){
c=newhash.table[i];
while(c!=NULL){
add(c->key,c->value,1);
c=c->next;
}
}
}
int main() {
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
hashTable<numar, int> hasht(666013);
numar y,ct;
ct.val=1;
int n,i,tip, x;
scanf("%d ", &n);
for (i = 1; i <= n; i++)
{
scanf("%d %d", &tip, &x);
y.val=x;
if(tip==1 && hasht.get(y)==0){
hasht.add(y, 0, 1);
continue;
}
if(tip==2){
hasht.remove(y);
continue;
}
if(tip==3){
fputs(hasht.get(y) ? "1\n" : "0\n", stdout);
continue;
}
}
return 0;
}