#include <bits/stdc++.h>
using namespace std;
int n;
int c[100001];
int ans[100001];
int used[100001], used_top;
bool visited[100001];
struct node {
  int type, time, col, num;
} q[100001];
inline bool cmp(node x, node y) {
  if (x.col != y.col)
    return x.col < y.col;
  else
    return x.num < y.num;
}
inline void update(int x, int delta) {
  while (x <= n) {
    c[x] += delta;
    if (!visited[x]) {
      visited[x] = true;
      used[++used_top] = x;
    }
    x += x & (-x);
  }
}
inline int query(int x) {
  int res = 0;
  while (x >= 1) {
    res += c[x];
    x -= x & (-x);
  }
  return res;
}
inline bool cmp_time(node x, node y) { return x.time < y.time; }
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &q[i].type, &q[i].time, &q[i].col);
    q[i].num = i;
  }
  sort(q + 1, q + n + 1, cmp_time);
  int cur_time = 1;
  for (i = 2; i <= n; i++)
    if (q[i].time == q[i - 1].time)
      q[i - 1].time = cur_time;
    else
      q[i - 1].time = cur_time++;
  q[n].time = cur_time;
  sort(q + 1, q + n + 1, cmp);
  memset(ans, -1, sizeof(ans));
  for (i = 1; i <= n; i++) {
    bool flag = false;
    for (k = i; q[k].col == q[k + 1].col && k <= n - 1; k++) {
      if (q[k].type == 3) flag = true;
    }
    if (!flag && q[k].type != 3) {
      i = k;
      continue;
    }
    memset(c, 0, sizeof(c));
    used_top = 0;
    for (j = i; j <= k; j++) {
      if (q[j].type == 1) update(q[j].time, 1);
      if (q[j].type == 2) update(q[j].time, -1);
      if (q[j].type == 3) ans[q[j].num] = query(q[j].time);
    }
    i = k;
  }
  for (i = 1; i <= n; i++)
    if (ans[i] > -1) printf("%d\n", ans[i]);
  return 0;
}
