#include<fstream>
#include<cstdio>
#include<cstdlib>
#define MARCAJ -14123
#define tip int
#define c1 131
#define c2 29
using namespace std;
int prim(int N){
if(N%2==0)N++;
int ok=0,i;
while(ok==0){
for(i=2;i<N/2;i++)
if(N%i==0){
N+=2;
i=2;
}
ok=1;}
return N;
}
void aloc(tip *&V,int M){
V=(tip*)calloc(M,sizeof(tip));
}
int h1(int M,tip x,int r){
long long c;
c=x;
c*=r;
c%=M;
return c;
}
int h2(int M,tip x,int i,int r){
int y;
y=(h1(M,x,r)+c1*i+c2*i)%M;
return y;
}
int cautare(tip *V,int M,tip x,int r){
int i=0,j;
do{
j=h2(M,x,i,r);
if(V[j]==x)return 1;
i++;
}while((i<M)&&(V[j]!=0));
return -1;
}
void inserare(tip *V,int M,tip x,int r){
int i=0,j;
do{
j=h2(M,x,i,r);
if((V[j]==0)||(V[j]==MARCAJ))V[j]=x;
i++;
}while((i<M)&&(V[j]!=x));
}
void sterge(tip *V,int M,tip x,int r){
int i=0,j;
if(cautare(V,M,x,r)==1){
do{
j=h2(M,x,i,r);
if(V[j]==x)
V[j]=MARCAJ;
i++;
}while(i<M);
}
}
main(){
int N,op,r,M;
tip *V,x;
register int i;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>N;
M=prim(N);
aloc(V,M);
r=rand();
for(i=1;i<=N;i++){
f>>op>>x;
if(op==1)inserare(V,M,x,r);
else if(op==2)sterge(V,M,x,r);
else if(op==3)
{
if(cautare(V,M,x,r)==-1)
g<<0<<'\n';
else g<<"1\n";
}
}
}