#include <iostream>
#define in "hashuri.in","r",stdin
#define out "hashuri.out","w",stdout
#include <cstdio>
#define nmax 1000001
using namespace std;
struct nod{
int e;
nod *next;
};
int n,h;
nod *H[nmax];
void Init(){
for(int i = 0; i < n; i++)
H[i] = NULL;
}
int lsearch(int x,long long k){
nod *L;
for(L = H[x];L!=NULL;L=L->next) if(L->e == k) return 1;
if(L==NULL) return 0;
return 1;
}
inline int h1(int x){
return x/n;
}
void add(long long x,int poz){
nod *L;
L=new nod;
L->e = x;
L->next = H[poz];
H[poz] = L;
}
void sterge(long long x , int poz){
nod *L;
L=new nod;
int ok = 1;
if(lsearch(poz,x)){
if(H[poz]->next == NULL) {
H[poz] = NULL;}
else{
for(L = H[poz] ; L!=NULL && L->e!=x;L=L->next) ;
if(L->next == NULL) L=NULL;
else{
L -> e = L->next->e;
L->next=L->next->next;}
H[poz] = L;
}
}}
void Read(){
int x,cod;
freopen(in);
freopen(out);
scanf("%d",&n);
Init();
for(int i=1;i<=n;i++){
scanf("%d%d",&cod,&x);
if(cod == 1)
{
if(!lsearch(h1(x),x)) add(x,h1(x));
}
else if(cod == 2) sterge(x,h1(x));
else if(cod == 3 ) {
if(lsearch(h1(x),x))
cout <<1<<'\n';
else cout << 0<<'\n';
}
}
}
int main(){
Read();
return 0;
}