#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int hmax = 0;
int hc;
long long roT,rotc;
long long roTdel, rotcdel;
class Treap{
public:
Treap *st,*dr;
int info, priority, weight;
Treap(){
st = dr = 0;
info = priority = weight = 0;
}
Treap(Treap *left, Treap *right, int priority,int info, int weight) {
this->st = left;
this->dr = right;
this->priority = priority;
this->info = info;
this->weight = weight;
}
}*Root, *Neal;
void update(Treap *&T){
T->weight = T->st->weight + T->dr->weight + 1;
}
void rotateLeft(Treap *&T){
++rotc;
Treap *aux = T->dr;
T->dr = aux->st;
aux->st = T;
T = aux;
update(T->st);
update(T);
}
void rotateRight(Treap *&T){
++rotc;
Treap *aux = T->st;
T->st = aux->dr;
aux->dr = T;
T = aux;
update(T->dr);
update(T);
}
void balance(Treap *&T){
if(T->priority < T->st->priority)
rotateRight(T);
else
if(T->priority < T->dr->priority)
rotateLeft(T);
}
void weightBalance(Treap *&T){
if(T->st->weight - 1 > T->dr->weight)
rotateRight(T);
else
if(T->dr->weight - 1 > T->st->weight)
rotateLeft(T);
}
bool isIn(Treap *T, int k){
++hc;
hmax = max(hc,hmax);
if(T == Neal) /// :D
return false;
if(T->info == k)
return true;
if(k < T->info)
return isIn(T->st, k);
return isIn(T->dr,k);
}
void Insert(Treap *&T, int k, int priority){
if(T == Neal){
T = new Treap(Neal, Neal, priority, k, 1);
return;
}
if(k < T->info)
Insert(T->st, k, priority);
else
Insert(T->dr, k, priority);
T->weight += 1;
weightBalance(T);
}
void Delete(Treap *&T, int k){
if(k < T->info)
Delete(T->st, k);
else
if(k > T->info)
Delete(T->dr, k);
else{
if(T->st == Neal && T->dr == Neal){
delete T;
T = Neal;
return;
}
if(T->st->weight > T->dr->weight) {
rotateRight(T);
Delete(T->dr, k);
}
else {
rotateLeft(T);
Delete(T->st, k);
}
}
}
#define DIM 66613
char buffer[DIM];
int poz = DIM - 1;
void scan(int &A)
{
A = 0;
while('0' > buffer[poz] || buffer[poz] > '9')
if(++poz == DIM) fread(buffer,1,DIM,stdin),poz = 0;
while('0' <= buffer[poz] && buffer[poz] <= '9')
{
A = A * 10 + buffer[poz] - 48;
if(++poz == DIM)
fread(buffer,1,DIM,stdin),poz = 0;
}
}
int check(Treap *T){
int rez = 0;
if(T == Neal)
return rez;
rez = 1 + check(T->st) + check(T->dr);
if(rez != T->weight)
cerr << "wrong!!\n";
return rez;
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
srand(time(0));
Neal = new Treap(0, 0, -INF, -INF, 0);
Neal->st = Neal;
Neal->dr = Neal;
Root = Neal;
int nri = 0,nrd = 0;
int N,op,x;
scan(N);
for(int i = 0; i < N; ++i){
scan(op);scan(x);
if(op == 1){
hc = 0;
if(isIn(Root, x))
continue;
rotc = 0;
Insert(Root, x, rand());
roT += rotc;
++nri;
continue;
}
if(op == 2){
hc = 0;
if(!isIn(Root, x))
continue;
rotc = 0;
Delete(Root, x);
roTdel += rotc;
++nrd;
continue;
}
hc = 0;
printf("%d\n",isIn(Root, x));
}
if(!nrd)
nrd = 1;
if(!nri)
nri = 1;
cerr << hmax << " " << static_cast<long double>(roT) / static_cast<long double>(nri) << " "
<< static_cast<long double>(roTdel) / static_cast<long double>(nrd);
check(Root);
return 0;
}