#include <cstdio>
#include <vector>
#define fi first
#define se second
using namespace std;
const int HSIZE = 3041;
const double knt = 0.61803398;
const pair <int,int> DELETED = make_pair(-1,-1);
typedef vector< pair<int,int> > my_hash[HSIZE];
my_hash hash1, hash2;
int h(int x,int i) {
if(i==1)
return int( (double(x * knt) - int(x * knt)) * (HSIZE-1) );
else
return x % HSIZE;
}
int search(my_hash hash,int x,int i)
{
int hh = h(x,i);
for(int i = hash[hh].size() - 1; i >= 0; --i)
if(hash[hh][i] . fi == x) return i;
return -1;
}
int search_r(int x)
{
if(search(hash1,x,1) != -1 || search(hash2,x,2) != -1)
return 1;
return 0;
}
void insert(my_hash hash,int x,int i,int t) {
int hh = h(x,i);
if(t == -1)
hash[hh].push_back(make_pair(x,1));
else hash[hh][t] . se ++;
}
void insert_r(int x)
{
int t;
if( (t = search(hash1,x,1)) != -1 )
{/*insert(hash1,x,1,t);*/ return;}
if( (t = search(hash2,x,2)) != -1 )
{/*insert(hash2,x,2,t);*/ return;}
int hh1 = h(x,1), hh2 = h(x,2);
hash1[hh1].size() < hash2[hh2].size() ?
insert(hash1,x,1,-1) : insert(hash2,x,2,-1);
}
int erase(my_hash hash,int x,int i) {
int hh = h(x,i);
for(int i = 0 ; i < (int)hash[hh].size(); ++i)
if(hash[hh][i] . fi == x)
{
if(hash[hh][i] . se == 1)
hash[hh].erase(hash[hh].begin() + i);
else hash[hh][i] . se --;
return 1;
}
return 0;
}
void erase_r(int x) {
if(!erase(hash1,x,1))
erase(hash2,x,2);
}
int count(my_hash hash,int x,int i) {
if(x<0) return 0;
int hh = h(x,i);
for(int i = hash[hh].size() - 1; i >= 0; --i)
{
if(hash[hh][i] . fi == x) return hash[hh][i] . se;
}
return 0;
}
int count_r(int x) {
int cnt = count(hash1,x,1);
if(!cnt)
cnt = count(hash2,x,2);
return cnt;
}
int main() {
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int K;
scanf("%d",&K);
int op,x;
while(K--)
{
scanf("%d%d",&op,&x);
switch(op) {
case 1: insert_r(x); break;
case 2: erase_r(x); break;
case 3: printf("%d\n",search_r(x)); break;
}
}
return 0;
}