#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int ans[N];
int ft[N];
void upd(int pos, int val) {
  while (pos < N) {
    ft[pos] += val;
    pos += pos & -pos;
  }
}
int query(int pos) {
  int ret = 0;
  while (pos) {
    ret += ft[pos];
    pos -= pos & -pos;
  }
  return ret;
}
vector<tuple<int, int, int> > q[N];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> comp;
  map<int, int> who;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int a, t, x;
    scanf("%d %d %d", &a, &t, &x);
    comp.push_back(t);
    if (!who.count(x)) who[x] = cnt++;
    x = who[x];
    q[x].emplace_back(a, t, i);
  }
  sort(comp.begin(), comp.end());
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < q[i].size(); j++) {
      int a, t, id;
      tie(a, t, id) = q[i][j];
      t = lower_bound(comp.begin(), comp.end(), t) - comp.begin();
      t++;
      get<1>(q[i][j]) = t;
      if (a == 1)
        upd(t, 1);
      else if (a == 2)
        upd(t, -1);
      else
        ans[id] = query(t);
    }
    for (int j = 0; j < q[i].size(); j++) {
      int a, t, id;
      tie(a, t, id) = q[i][j];
      if (a == 1)
        upd(t, -1);
      else if (a == 2)
        upd(t, 1);
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] != -1) printf("%d\n", ans[i]);
  }
  return 0;
}
