#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
int n;
int a[MAXN], t[MAXN], x[MAXN];
vector<int> tt[MAXN];
vector<int> fen[MAXN];
set<int> xx;
map<int, int> xg;
int get(int k, int i) {
  int res = 0;
  while (i >= 0) {
    res += fen[k][i];
    i = (i & (i + 1)) - 1;
  }
  return res;
}
void update(int k, int i, int s) {
  while (i < (int)fen[k].size()) {
    fen[k][i] += s;
    i = (i | (i + 1));
  }
}
int ff(int k, int t) {
  int l = 0, r = (int)tt[k].size() - 1;
  while (l <= r) {
    int z = (l + r) / 2;
    if (tt[k][z] >= t)
      r = z - 1;
    else
      l = z + 1;
  }
  return l;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> t[i] >> x[i];
    if (a[i] == 3) xx.insert(x[i]);
  }
  auto it = xx.begin();
  int id = 0;
  while (it != xx.end()) {
    xg[*it] = id;
    ++id;
    ++it;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == 3) tt[xg[x[i]]].push_back(t[i]);
  }
  int kol = xx.size();
  for (int i = 0; i < kol; ++i) {
    sort(tt[i].begin(), tt[i].end());
    fen[i].resize(tt[i].size(), 0);
  }
  for (int i = 0; i < n; ++i) {
    if (xg.find(x[i]) == xg.end()) continue;
    int k = xg[x[i]];
    int tim = ff(k, t[i]);
    if (a[i] == 1) {
      update(k, tim, 1);
    } else {
      if (a[i] == 2)
        update(k, tim, -1);
      else
        cout << get(k, tim) << '\n';
    }
  }
  return 0;
}
