#include <bits/stdc++.h>
using namespace std;
int n, g[100005], ans[100005];
struct z {
  int op, id, x, t;
} a[100005];
bool cam(z d, z e) {
  if (d.x == e.x) return d.id < e.id;
  return d.x < e.x;
}
int t[100005];
void add(int x, int c) {
  for (; x <= n; x += x & (-x)) t[x] += c;
}
int sum(int x) {
  int res = 0;
  for (; x; x -= x & (-x)) res += t[x];
  return res;
}
int main() {
  cin >> n;
  memset(ans, -1, sizeof(ans));
  for (int i = 1; i <= n; i++)
    scanf("%d%d%d", &a[i].op, &a[i].t, &a[i].x), a[i].id = i, g[i] = a[i].t,
                                                 a[i].id = i;
  sort(g + 1, g + 1 + n);
  int tot = unique(g + 1, g + 1 + n) - g - 1;
  for (int i = 1; i <= n; i++) {
    int l = 0, r = tot + 1;
    while (l + 1 < r) {
      int mid = l + r >> 1;
      if (g[mid] <= a[i].t)
        l = mid;
      else
        r = mid;
    }
    a[i].t = l;
  }
  sort(a + 1, a + n + 1, cam);
  int pre;
  for (int i = 1; i <= n; i++) {
    int j;
    for (j = i; j <= n + 1; j++)
      if (a[i].x != a[j + 1].x) break;
    pre = j;
    for (int j = i; j <= pre; j++) {
      if (a[j].op == 1)
        add(a[j].t, 1);
      else if (a[j].op == 2)
        add(a[j].t, -1);
      else
        ans[a[j].id] = sum(a[j].t);
    }
    for (int j = i; j <= pre; j++) {
      if (a[j].op == 1)
        add(a[j].t, -1);
      else if (a[j].op == 2)
        add(a[j].t, 1);
    }
    i = pre;
  }
  for (int i = 1; i <= n; i++)
    if (ans[i] != -1) printf("%d\n", ans[i]);
}
