#include <bits/stdc++.h>
using namespace std;
struct fish {
  int sys, t, x, id;
} a[112345];
int n, cnt, ans[112345], tmp[112345], box[112345];
bool cmp(fish p, fish q) { return p.t < q.t; }
void TieTie() {
  int lsh[112345];
  for (int i = 1; i <= n; i++) lsh[i] = tmp[i];
  sort(lsh + 1, lsh + n + 1);
  int siz = unique(lsh + 1, lsh + n + 1) - lsh - 1;
  for (int i = 1; i <= n; i++)
    tmp[i] = lower_bound(lsh + 1, lsh + siz + 1, tmp[i]) - lsh;
}
void CDQdopart(int l, int r) {
  if (l == r) return;
  int mid = (l + r) / 2;
  CDQdopart(l, mid);
  CDQdopart(mid + 1, r);
  sort(a + l, a + mid + 1, cmp);
  sort(a + mid + 1, a + r + 1, cmp);
  int zuo = l, you = mid;
  for (you = mid + 1; you <= r; you++) {
    if (a[you].sys != 3) continue;
    while (a[zuo].t <= a[you].t) {
      if (zuo > mid) break;
      if (a[zuo].sys == 1) box[a[zuo].x]++;
      if (a[zuo].sys == 2) box[a[zuo].x]--;
      zuo++;
    }
    ans[a[you].id] += box[a[you].x];
  }
  for (int i = l; i < zuo; i++) {
    if (a[i].sys == 1) box[a[i].x]--;
    if (a[i].sys == 2) box[a[i].x]++;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].sys, &a[i].t, &tmp[i]);
    if (a[i].sys == 3) {
      cnt++;
      a[i].id = cnt;
    }
  }
  TieTie();
  for (int i = 1; i <= n; i++) a[i].x = tmp[i];
  CDQdopart(1, n);
  for (int i = 1; i <= cnt; i++) printf("%d\n", ans[i]);
}
