#include <bits/stdc++.h>
using namespace std;
const int oo = 0x7fffffff;
int Hash[1000007], hn, ans[1000007];
struct da {
  int l, r, val;
  int mid() { return (l + r) / 2; }
  int len() { return (r - l + 1); }
} tree[1000007 << 2];
struct node {
  int op, time, num, id;
  bool operator<(const node& a) const {
    if (num != a.num) return num < a.num;
    return id < a.id;
  }
} fuck[1000007];
int Find(int k, int n) {
  int cnt;
  cnt = Hash[0] = 0;
  hn = 1;
  for (int i = k; i < n; i++) {
    if (fuck[i].num != fuck[k].num) break;
    cnt++;
    Hash[hn++] = fuck[i].time;
  }
  return cnt;
}
void build(int l, int r, int rt) {
  tree[rt].l = l;
  tree[rt].r = r;
  tree[rt].val = 0;
  int mid = tree[rt].mid();
  if (l == r) return;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
}
void update(int rt, int t, int x) {
  tree[rt].val += x;
  if (tree[rt].l == tree[rt].r) return;
  if (t <= tree[rt << 1].r)
    update(rt << 1, t, x);
  else
    update(rt << 1 | 1, t, x);
}
int query(int rt, int l, int r) {
  if (tree[rt].l == l && tree[rt].r == r) return tree[rt].val;
  int mid = tree[rt].mid();
  int ans;
  if (r <= tree[rt << 1].r)
    ans = query(rt << 1, l, r);
  else if (l > tree[rt << 1].r)
    ans = query(rt << 1 | 1, l, r);
  else
    ans = query(rt << 1, l, mid) + query(rt << 1 | 1, mid + 1, r);
  return ans;
}
int main() {
  int i, n, len;
  while (scanf("%d", &n) != EOF) {
    memset(ans, -1, sizeof(ans));
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &fuck[i].op, &fuck[i].time, &fuck[i].num);
      fuck[i].id = i;
    }
    sort(fuck, fuck + n);
    i = 0;
    while (i < n) {
      len = Find(i, n);
      sort(Hash, Hash + hn);
      build(1, hn, 1);
      while (len--) {
        int t = lower_bound(Hash, Hash + hn, fuck[i].time) - Hash;
        if (fuck[i].op == 1)
          update(1, t, 1);
        else if (fuck[i].op == 2)
          update(1, t, -1);
        else
          ans[fuck[i].id] = query(1, 1, t);
        i++;
      }
    }
    for (i = 0; i < n; i++)
      if (ans[i] != -1) printf("%d\n", ans[i]);
  }
  return 0;
}
