#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 50;
struct Q {
  int a, t, x, id;
  void print() { printf("%d %d %d %d\n", a, t, x, id); }
} q[N], tmp[N];
struct Orz {
  vector<int> a;
  void clr() { a.clear(); }
  void add(int x) { a.push_back(x); }
  int siz() { return a.size(); }
  void work() {
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
  }
  int idx(int x) { return lower_bound(a.begin(), a.end(), x) - a.begin() + 1; }
  int val(int i) { return a[i - 1]; }
} orz;
struct BIT {
  int c[N];
  int n;
  void init(int siz) { n = siz; }
  int lowbit(int x) { return x & (-x); }
  void add(int i, int x) {
    while (i <= n) {
      c[i] += x;
      i += lowbit(i);
    }
  }
  int sum(int i) {
    int ans = 0;
    while (i) {
      ans += c[i];
      i -= lowbit(i);
    }
    return ans;
  }
} bit;
int n, ans[N], cnt;
void cdq(int l, int r) {
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  cdq(l, mid);
  cdq(mid + 1, r);
  queue<int> cs;
  int p1 = l, p2 = mid + 1;
  int ps = l;
  while (p1 <= mid && p2 <= r) {
    if (q[p1].t < q[p2].t) {
      if (q[p1].a == 1) {
        bit.add(q[p1].x, 1);
      } else if (q[p1].a == 2) {
        bit.add(q[p1].x, -1);
      }
      cs.push(p1);
      tmp[ps++] = q[p1++];
    } else {
      if (q[p2].a == 3) {
        ans[q[p2].id] += bit.sum(q[p2].x) - bit.sum(q[p2].x - 1);
      }
      tmp[ps++] = q[p2++];
    }
  }
  while (p1 <= mid) {
    tmp[ps++] = q[p1++];
  }
  while (p2 <= r) {
    if (q[p2].a == 3) {
      ans[q[p2].id] += bit.sum(q[p2].x) - bit.sum(q[p2].x - 1);
    }
    tmp[ps++] = q[p2++];
  }
  while (!cs.empty()) {
    int u = cs.front();
    if (q[u].a == 1) {
      bit.add(q[u].x, -1);
    } else if (q[u].a == 2) {
      bit.add(q[u].x, 1);
    }
    cs.pop();
  }
  for (int i = l; i <= r; i++) {
    q[i] = tmp[i];
  }
}
int main() {
  scanf("%d", &n);
  orz.clr();
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &q[i].a, &q[i].t, &q[i].x);
    if (q[i].a == 3) {
      q[i].id = ++cnt;
    }
    orz.add(q[i].t);
    orz.add(q[i].x);
  }
  orz.work();
  for (int i = 1; i <= n; i++) {
    q[i].t = orz.idx(q[i].t);
    q[i].x = orz.idx(q[i].x);
  }
  bit.init(orz.siz());
  cdq(1, n);
  for (int i = 1; i <= cnt; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
