#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod) {
  x += y;
  if (x >= mod) x -= mod;
}
void et() {
  puts("-1");
  exit(0);
}
struct mb {
  int a, t, x, id;
  void rd() { scanf("%d%d%d", &a, &t, &x); }
  bool operator<(const mb &o) const { return t < o.t; }
} q[100005];
vector<pair<int, int>> ans;
map<int, vector<int>> mp;
map<int, int> tid;
int cnt;
int a[100005], b[100005];
void update(int x, int val) {
  for (int i = x; i <= cnt; i += i & -i) {
    b[i] += val;
  }
}
int query(int x) {
  int ret = 0;
  for (; x > 0; ret += b[x], x -= x & -x)
    ;
  return ret;
}
void fmain() {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    q[i].rd();
    q[i].id = i;
    mp[q[i].x].push_back(i);
    tid[q[i].t];
  }
  for (auto &p : tid) p.second = ++cnt;
  for (auto &p : mp) {
    vector<int> v;
    for (int id : p.second) {
      int t = tid[q[id].t], ope = q[id].a;
      if (ope == 1) {
        update(t, 1);
        a[t]++;
        v.push_back(t);
      } else if (ope == 2) {
        update(t, -1);
        a[t]--;
        v.push_back(t);
      } else {
        ans.push_back({id, query(t)});
      }
    }
    for (int t : v) {
      update(t, -a[t]);
      a[t] = 0;
    }
  }
  sort(ans.begin(), ans.end());
  for (auto p : ans) printf("%d\n", p.second);
}
int main() {
  fmain();
  return 0;
}
