#include<fstream>
#define MARCAJ -14123
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(int *&V,int M){
V=(int*)calloc(M,sizeof(int));
}
int h1(int M, int x,int r){
long long c;
c=x;
c*=r;
c%=M;
return c;
}
int h2(int M, int x,int i,int r){
int y,c1=131,c2=29;
y=(h1(M,x,r)+c1*i+c2*i*i)%M;
return y;
}
int cautare(int *V,int M,int 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(int *V,int M, int 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(int *V,int M,int 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);
}
}
int main(){
int N,*V,op,x,r,M;
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";
}
}
}