#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
map<int,int> fen[100001];
int type[100001];
int t[100001];
int x[100001];
pbds times;
const int N = 100001;
void add(int idx ,int val){
while (idx <= N){
fen[idx][val]++;
idx += (idx & -idx);
}
}
void remove(int idx ,int val){
while (idx <= N){
fen[idx][val]--;
idx += (idx & -idx);
}
}
int read(int idx, int val){
int sum = 0;
while (idx > 0){
sum += fen[idx][val];
idx -= (idx & -idx);
}
return sum;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n;
cin >> n;
int a, b, c;
for(int i = 0; i < n; i++)
{
cin >> a >> b >> c;
type[i] = a;
t[i] = b;
x[i] = c;
times.insert(b);
}
for(int i = 0; i < n; i++)
{
a = type[i];
b = times.order_of_key(t[i])+1;
c = x[i];
if(a == 1) add(b, c);
if(a == 2) remove(b, c);
if(a == 3) cout << read(b, c) << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LGludD4gaWk7CnR5cGVkZWYgdmVjdG9yPGludD4gdmk7CgojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCgp0eXBlZGVmI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