#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int n, cnt, ton[300010];
struct node {
  int opt, t, x, ti, ans;
} a[300010], tmp[300010];
bool cmp(node a, node b) { return a.ti < b.ti; }
void CDQ(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  CDQ(l, mid), CDQ(mid + 1, r);
  int t1 = l, t2 = mid + 1, now = l;
  while (t1 <= mid || t2 <= r) {
    if (t1 <= mid && a[t1].t < a[t2].t || t2 > r) {
      if (a[t1].opt == 1) ton[a[t1].x]++;
      if (a[t1].opt == 2) ton[a[t1].x]--;
      tmp[now++] = a[t1++];
    } else {
      if (a[t2].opt == 3) a[t2].ans += ton[a[t2].x];
      tmp[now++] = a[t2++];
    }
  }
  for (int i = l; i <= mid; i++) {
    if (a[i].opt == 1) ton[a[i].x]--;
    if (a[i].opt == 2) ton[a[i].x]++;
  }
  for (int i = l; i <= r; i++) a[i] = tmp[i];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].opt, &a[i].t, &a[i].x);
    if (!mp[a[i].x]) mp[a[i].x] = ++cnt;
    a[i].x = mp[a[i].x];
    a[i].ti = i;
  }
  CDQ(1, n), sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++)
    if (a[i].opt == 3) printf("%d\n", a[i].ans);
  return 0;
}
