#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  int y;
  long long x, sum;
  int sgn;
  node *l, *r;
  node(int y = 0, long long x = 0, int sgn = 1, node *left = NULL,
       node *right = NULL)
      : y(y), x(x), l(left), r(right) {
    sum = sgn;
    this->sgn = sgn;
  }
  ~node() {
    delete l;
    delete r;
  }
};
typedef node *pnode;
class treap {
 public:
  static void merge(pnode &t, pnode l, pnode r) {
    if (!l || !r)
      t = l ? l : r;
    else if (l->y > r->y)
      merge(l->r, l->r, r), t = l;
    else
      merge(r->l, l, r->l), t = r;
    recalc(t);
  }
  static void split(pnode t, long long x, pnode &l, pnode &r) {
    if (!t)
      l = r = NULL;
    else if (t->x > x)
      split(t->l, x, l, t->l), r = t, recalc(r);
    else if (t->x <= x)
      split(t->r, x, t->r, r), l = t, recalc(l);
  }
  static void recalc(pnode t) {
    if (!t) return;
    t->sum = sum_of(t->l) + sum_of(t->r) + t->sgn;
  }
  static long long sum_of(pnode t) { return t ? t->sum : 0; }
};
pnode find(long long x, pnode t) {
  if (!t) return 0;
  if (t->x == x) {
    return t;
  } else if (x < t->x) {
    if (t->l)
      return find(x, t->l);
    else
      return t;
  } else {
    if (t->r)
      return find(x, t->r);
    else
      return t;
  }
}
void add(pnode &t, long long x, int sgn) {
  if (!t) {
    t = new node(rand(), x, sgn);
    return;
  }
  pnode tmp = find(x, t);
  if (tmp && tmp->x == x) {
    sgn += tmp->sgn;
    sgn = min(sgn, 1);
    pnode l = NULL, r = NULL;
    treap::split(t, x, l, r);
    l->sgn = sgn;
    treap::recalc(l);
    treap::merge(t, l, r);
    return;
  }
  pnode l = NULL, r = NULL;
  treap::split(t, x, l, r);
  treap::merge(l, l, new node(rand(), x, sgn));
  treap::merge(t, l, r);
}
long long sum(pnode &t, long long x, long long y) {
  long long s = 0;
  pnode l = NULL, m = NULL, r = NULL;
  treap::split(t, x - 1, l, r);
  treap::split(r, y, m, r);
  s = treap::sum_of(m);
  treap::merge(r, m, r);
  treap::merge(t, l, r);
  return s;
}
int n;
unordered_map<int, pnode> a;
void add(int x, int t) {
  if (a[x] == 0) {
    pnode tmp = 0;
    add(tmp, t, 1);
    a[x] = tmp;
  } else
    add(a[x], t, 1);
}
void rem(int x, int t) { add(a[x], t, -1); }
int cnt(int x, int t) {
  int s = sum(a[x], 0, t);
  return s;
}
int main() {
  cin >> n;
  while (n--) {
    int a, t, x;
    cin >> a >> t >> x;
    if (a == 1) {
      add(x, t);
    } else if (a == 2) {
      rem(x, t);
    } else if (a == 3) {
      cout << cnt(x, t) << '\n';
    }
  }
  return 0;
}
